315157973 opened a new pull request #9740:
URL: https://github.com/apache/pulsar/pull/9740


   
   
   Fixes #9709 & #9711
   
   ### Motivation
   ```
   Caused by: java.lang.NullPointerException
        at java.util.TreeMap.getEntry(TreeMap.java:347)
   ```
   From the stack trace, it is caused by the key read by `TreeMap` being null. 
Therefore, the role must be null.
   ```
   //PulsarAuthorizationProvider.java:404
   Map<String, Set<AuthAction>> namespaceRoles = 
policies.get().auth_policies.namespace_auth;
   Set<AuthAction> namespaceActions = namespaceRoles.get(role);
   ```
   
   According to the code, the role is read through `httpRequest.getAttribute` 
in `PulsarWebResource#clientAppId`, so it is normal to be null.
   
   Although the role is null, why do unit tests pass occasionally?
   I added the log and found that the implementation class of Map is not always 
TreeMap, but occasionally HashMap.
   When it is a HashMap, no error will be reported if the key is null. This 
problem is caused by Jackson's serialization.
   
   I checked AuthPolicies, all Maps are initialized as TreeMap, but we have 
never used any features of TreeMap. 
   In order to avoid serialization problems elsewhere, I changed TreeMap to 
HashMap.
   Another way is to add the annotation @JsonDeserialize(as = TreeMap.class), 
and then make the judgment that the key is null.
   Why was TreeMap used here? May need @merlimat  to help explain.
   


----------------------------------------------------------------
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:
[email protected]


Reply via email to