apache/shenyu · error · ShenyuAdminException
The default namespace cannot delete!
Error message
The default namespace cannot delete!
What it means
Thrown by NamespaceServiceImpl.delete when the id list includes the built-in default namespace primary key (Constants.DEFAULT_NAMESPACE_PRIMARY_KEY). ShenYu protects the default namespace from deletion because the gateway and bootstrap config depend on it.
Solutions
- Remove the default namespace id from the ids list before calling delete
- Filter in UI/scripts: exclude Constants.DEFAULT_NAMESPACE_PRIMARY_KEY from batch deletion
- Operate only on custom-created namespaces
Example fix
// before
namespaceService.delete(allIds);
// after
List<String> deletable = allIds.stream()
.filter(id -> !Constants.DEFAULT_NAMESPACE_PRIMARY_KEY.equals(id))
.collect(Collectors.toList());
if (!deletable.isEmpty()) {
namespaceService.delete(deletable);
} Defensive patterns
Strategy: validation
Validate before calling
if (ids.contains(Constants.DEFAULT_NAMESPACE_PRIMARY_KEY)) {
throw new IllegalArgumentException("default namespace cannot be deleted");
} Try / catch
try {
namespaceService.delete(ids);
} catch (ShenyuAdminException e) {
if (AdminConstants.SYS_DEFAULT_NAMESPACE_ID_DELETE.equals(e.getMessage())) {
LOG.warn("default namespace excluded from deletion");
} else {
throw e;
}
} Prevention
- Never include the default namespace id in batch deletes
- Filter protected ids in UI selections and scripts
- Document the protected default namespace for operators
When it happens
Trigger: Calling DELETE /namespace with ids containing the default namespace id ('1' by default); batch-selecting all rows in the dashboard including the default namespace and deleting; scripts that enumerate namespaces and pass every id.
Common situations: Bulk cleanup scripts that do not filter the default namespace; admins unfamiliar with the namespace model trying to remove the pre-provisioned namespace.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- shenyu this discovery is not found in current namespace
- The namespace(s) does not exist!
- rule exist under those namespace!
- selector exist under those namespace!
- Plugins exist under those namespace!
AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12).
Data as JSON: /api/errors/f4d0d773039ef032.
Report an issue: GitHub.
Appendix: source
Thrown at shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespaceServiceImpl.java:137
List<NamespaceDO> allList = namespaceMapper.selectAll();
namespaceIds = allList.stream().map(NamespaceDO::getNamespaceId).toList();
} else {
namespaceIds = namespaceUserService.listNamespaceIdByUserId(SessionUtil.visitorId());
}
if (CollectionUtils.isEmpty(namespaceIds)) {
return new CommonPager<>();
}
namespaceQuery.setNamespaceIds(namespaceIds);
return PageResultUtils.result(namespaceQuery.getPageParameter(), () -> namespaceMapper.countByQuery(namespaceQuery), () -> namespaceMapper.selectByQuery(namespaceQuery)
.stream()
.map(NamespaceTransfer.INSTANCE::mapToVo)
.collect(Collectors.toList()));
}
@Override
public String delete(final List<String> ids) {
if (ids.contains(Constants.DEFAULT_NAMESPACE_PRIMARY_KEY)) {
throw new ShenyuAdminException(AdminConstants.SYS_DEFAULT_NAMESPACE_ID_DELETE);
}
List<String> namespaceIdList = namespaceMapper.selectByIds(ids).stream().map(NamespaceDO::getNamespaceId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(namespaceIdList)) {
throw new ShenyuAdminException(AdminConstants.SYS_NAMESPACE_ID_NOT_EXIST);
}
List<RuleDO> ruleDOList = ruleMapper.selectAllByNamespaceIds(namespaceIdList);
if (CollectionUtils.isNotEmpty(ruleDOList)) {
throw new ShenyuAdminException("rule exist under those namespace!");
}
List<SelectorDO> selectorDOS = selectorMapper.selectAllByNamespaceIds(namespaceIdList);
if (CollectionUtils.isNotEmpty(selectorDOS)) {
throw new ShenyuAdminException("selector exist under those namespace!");
}
List<NamespacePluginVO> namespacePluginVOS = namespacePluginRelMapper.selectAllByNamespaceIds(namespaceIdList);
if (CollectionUtils.isNotEmpty(namespacePluginVOS)) {
throw new ShenyuAdminException("Plugins exist under those namespace!");
}
List<MetaDataDO> metaDataDOList = metaDataMapper.findAllByNamespaceIds(namespaceIdList);View on GitHub (pinned to 567142e072)