This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 777f133 Fix NPE when privilegeType is null. (#14161)
777f133 is described below
commit 777f133218b3e5fc25805ee31020c91327eb5995
Author: Raigor <[email protected]>
AuthorDate: Mon Dec 20 09:25:13 2021 +0800
Fix NPE when privilegeType is null. (#14161)
---
.../apache/shardingsphere/authority/checker/AuthorityChecker.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git
a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java
b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java
index c02f899..93f9589 100644
---
a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java
+++
b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java
@@ -46,6 +46,7 @@ import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQ
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import java.util.function.BiPredicate;
@@ -75,9 +76,9 @@ public final class AuthorityChecker implements
SQLChecker<AuthorityRule> {
if (!privileges.filter(optional ->
optional.hasPrivileges(currentSchema)).isPresent()) {
return new SQLCheckResult(false, String.format("Unknown database
'%s'", currentSchema));
}
- // TODO add error msg
- return privileges.map(optional -> new
SQLCheckResult(optional.hasPrivileges(Collections.singletonList(getPrivilege(sqlStatement))),
- String.format("Access denied for operation %s",
getPrivilege(sqlStatement).name()))).orElseGet(() -> new SQLCheckResult(false,
""));
+ PrivilegeType privilegeType = getPrivilege(sqlStatement);
+ String errorMessage = Objects.isNull(privilegeType) ? "" :
String.format("Access denied for operation %s", privilegeType.name());
+ return privileges.map(optional -> new
SQLCheckResult(optional.hasPrivileges(Collections.singletonList(privilegeType)),
errorMessage)).orElseGet(() -> new SQLCheckResult(false, ""));
}
@Override