In ModerationRequestController.java, the getModerationRequestsByState method has a potential NullPointerException vulnerability when the state parameter is null.
Location
- File:
rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/moderationrequest/ModerationRequestController.java
- Line: 203
- Method:
getModerationRequestsByState
Issue
The method calls stateOptions.get(0).equalsIgnoreCase(state) without checking if state is null. If the state parameter is not provided, it will throw NullPointerException.
Current Code (buggy):
boolean stateOpen = stateOptions.get(0).equalsIgnoreCase(state);
Recommended Fix:
boolean stateOpen = "open".equalsIgnoreCase(state);
This is a standard Java idiom to avoid NullPointerException - by putting the constant string first, if state is null, it simply returns false instead of throwing an NPE.
How to reproduce
1. Call the moderation request API without providing the state parameter
2. The application will throw NullPointerException