Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix flaky-test: AuthorizationTest.simple (apache#9740)
Fixes apache#9709 ### 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 logs 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.
- Loading branch information