You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2021/01/12 17:03:45 UTC

[GitHub] [sling-org-apache-sling-feature-cpconverter] anchela commented on a change in pull request #46: SLING-9974: add nullability annotations

anchela commented on a change in pull request #46:
URL: https://github.com/apache/sling-org-apache-sling-feature-cpconverter/pull/46#discussion_r555917891



##########
File path: src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/AccessControlEntry.java
##########
@@ -34,31 +36,31 @@
 
     private final List<String> restrictions = new LinkedList<>();
 
-    public AccessControlEntry(boolean isAllow, String privileges, RepoPath repositoryPath) {
+    public AccessControlEntry(boolean isAllow, @Nullable String privileges, @NotNull RepoPath repositoryPath) {
         this.isAllow = isAllow;
         this.privileges = privileges;
         this.repositoryPath = repositoryPath;
     }
 
-    public void addRestriction(String restriction) {
+    public void addRestriction(@Nullable String restriction) {
         if (restriction != null && !restriction.isEmpty()) {
             restrictions.add(restriction);
         }
     }
 
-    public String getOperation() {
+    public @NotNull String getOperation() {
         return isAllow ? "allow" : "deny";
     }
 
-    public String getPrivileges() {
+    public @Nullable String getPrivileges() {

Review comment:
       afaik creating an ACE without specifying privileges will fail... and i suspect so does repo-init. imo this should return notnull

##########
File path: src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/AccessControlEntry.java
##########
@@ -34,31 +36,31 @@
 
     private final List<String> restrictions = new LinkedList<>();
 
-    public AccessControlEntry(boolean isAllow, String privileges, RepoPath repositoryPath) {
+    public AccessControlEntry(boolean isAllow, @Nullable String privileges, @NotNull RepoPath repositoryPath) {

Review comment:
       see below.... null privileges don't make too much sense.... i see where it is coming from (extractValue(attributes.getValue(REP_PRIVILEGES)) may return null).... but then maybe the constructor should throws an illegalargument exception or thee AbstractPolicyParser should make sure it never creates an entry for null privileges.

##########
File path: src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/DefaultAclManager.java
##########
@@ -268,7 +263,7 @@ private static void addAclStatement(Formatter formatter, String systemUser, List
         formatter.format("end%n");
     }
 
-    private static boolean areEmpty(List<AccessControlEntry> authorizations) {
+    private static boolean areEmpty(@Nullable List<AccessControlEntry> authorizations) {

Review comment:
       afaik see areEmpty is only call in `addAclStatement` and in `addPaths`. both define here that the list of AccessControlEntry to be notnull. shouldn't then the list be notnull here as well and the extra check of being null dropped?

##########
File path: src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/DefaultAclManager.java
##########
@@ -268,7 +263,7 @@ private static void addAclStatement(Formatter formatter, String systemUser, List
         formatter.format("end%n");
     }
 
-    private static boolean areEmpty(List<AccessControlEntry> authorizations) {
+    private static boolean areEmpty(@Nullable List<AccessControlEntry> authorizations) {
         return authorizations == null || authorizations.isEmpty();

Review comment:
       see above. if `authorizations` is notnull the extra check for null can be omitted.... and maybe the utility simply doesn't make too much sense then.... because i don't see too much benefit of calling areEmpty(List) over List.isEmpty.... (apart from the fact that the method name is just not reflecting what it does if it checks for null)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org