jeecgboot/JeecgBoot · error · RuntimeException
无效的拖拽位置
Error message
无效的拖拽位置
What it means
Thrown by the default case in updateChangeDepart's switch statement when dropPosition is not one of {-1, 0, 1}. This is a raw RuntimeException (not JeecgBootBizTipException), meaning it is an unexpected/programmatic error rather than a user-facing business tip. The switch expects -1 (above), 0 (inside as child), or 1 (below).
Source
Thrown at jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysDepartServiceImpl.java:2040
//3. 验证拖拽操作是否合法
validateDragOperation(dragDept, targetDept, changeDepartVo.getDropPosition());
//4. 根据dropPosition调整部门顺序
Integer dropPosition = changeDepartVo.getDropPosition();
switch (dropPosition) {
case -1:
// 拖拽到上方
moveToAbove(dragDept, targetDept);
break;
case 0:
// 拖拽到内部(作为子部门)
moveAsChild(dragDept, targetDept);
break;
case 1:
//拖拽到下方
moveToBelow(dragDept, targetDept, changeDepartVo.getSort());
break;
default:
throw new RuntimeException("无效的拖拽位置");
}
//5. 清空缓存
redisUtil.removeAll(CommonConstant.DEPART_NAME_REDIS_KEY_PRE);
}
/**
* 验证拖拽操作是否合法
*
* @param dragDept 被拖拽的部门
* @param targetDept 目标部门
* @param dropPosition 拖拽位置
*/
private void validateDragOperation(SysDepart dragDept, SysDepart targetDept, Integer dropPosition) {
// 禁止拖拽到自身
if (dragDept.getId().equals(targetDept.getId())) {
throw new RuntimeException("不能拖拽到自身");
}
// 禁止拖拽到自身子部门View on GitHub (pinned to 96fb33f5ec)
Solutions
- Inspect the dropPosition value being sent by the frontend — it must be exactly -1, 0, or 1.
- Fix the frontend drag handler to correctly map the drop location to one of the three valid positions.
- Add input validation at the controller layer to reject invalid dropPosition before reaching the service.
- If using a tree component library, verify its drop-position encoding matches the backend convention.
Example fix
// before
switch (dropPosition) {
case -1: moveToAbove(dragDept, targetDept); break;
case 0: moveAsChild(dragDept, targetDept); break;
case 1: moveToBelow(dragDept, targetDept, changeDepartVo.getSort()); break;
default: throw new RuntimeException("无效的拖拽位置");
}
// after — validate at the controller, use business exception in service
if (dropPosition == null || dropPosition < -1 || dropPosition > 1) {
throw new JeecgBootBizTipException("无效的拖拽位置,必须为 -1、0 或 1");
} Defensive patterns
Strategy: validation
Validate before calling
// Validate dropPosition before calling updateChangeDepart
Integer dropPosition = changeDepartVo.getDropPosition();
if (dropPosition == null || dropPosition < -1 || dropPosition > 1) {
return Result.error("无效的拖拽位置,必须为 -1(上方)、0(内部) 或 1(下方)");
}
service.updateChangeDepart(changeDepartVo); Type guard
public boolean isValidDropPosition(Integer position) {
return position != null && (position == -1 || position == 0 || position == 1);
} Try / catch
try {
service.updateChangeDepart(changeDepartVo);
} catch (RuntimeException e) {
if (e.getMessage().contains("无效的拖拽位置")) {
return Result.error("拖拽位置参数无效,请重新操作");
}
throw e;
} Prevention
- Map frontend drag events to exactly {-1, 0, 1} before sending.
- Add controller-layer validation for dropPosition range.
- Test drag interactions across different tree component versions.
When it happens
Trigger: Calling updateChangeDepart with a dropPosition value outside {-1, 0, 1}, such as null, 2, -2, or any other integer. Most commonly a frontend bug in computing the drop position from the drag event, or a malformed API request.
Common situations: Frontend drag library version change that alters position encoding; null dropPosition from a missing form field; API testing with an invalid integer; a new position type added to the UI without backend support.
Related errors
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/54b1e2d94a880822.
Report an issue: GitHub.