fix: handle DASHBOARD audit reference type to prevent NPE in audit log UI#16355
fix: handle DASHBOARD audit reference type to prevent NPE in audit log UI#16355moerradi wants to merge 1 commit intogravitee-io:masterfrom
Conversation
…g UI DASHBOARD was added to the repository-layer Audit.AuditReferenceType enum but was never propagated to the service-layer AuditReferenceType enum or the conversion map in AuditServiceImpl. This caused Map.get() to return null for any DASHBOARD audit record, which then triggered a NPE in getMetadata() where getReferenceType().name() was called without a null guard, making the entire audit log page fail to load.
There was a problem hiding this comment.
Code Review
This pull request adds the DASHBOARD audit reference type to the API model and updates the AuditServiceImpl to include it in the reference type mapping. The review feedback suggests simplifying the metadata enrichment logic by removing an unnecessary defensive null check and replacing string-based enum comparisons with direct enum equality checks to improve readability and type safety.
I am having trouble creating individual review comments. Click here to see my feedback.
gravitee-apim-rest-api/gravitee-apim-rest-api-service/src/main/java/io/gravitee/rest/api/service/impl/AuditServiceImpl.java (191-193)
Avoid adding defensive checks for scenarios that are considered impossible under the current architecture, such as using an empty if block to handle null reference types. Adhering to the YAGNI principle simplifies the code. Additionally, prioritize readability by using direct enum comparison (==) instead of comparing string names via .name().equals(), which also provides compile-time type safety.
if (AuditReferenceType.ORGANIZATION == auditEntity.getReferenceType()) {
References
- Avoid adding defensive checks for scenarios that are considered impossible under the current architecture, adhering to the YAGNI (You Ain't Gonna Need It) principle.
- Prioritize code simplicity and readability over micro-optimizations that do not address a real performance bottleneck.
Issue
gravitee-io/issues#11338.
Description
DASHBOARD was added to the repository-layer Audit.AuditReferenceType enum but was never propagated to the service-layer AuditReferenceType enum or the conversion map in AuditServiceImpl. This caused Map.get() to return null for any DASHBOARD audit record, which then triggered a NPE in getMetadata() where getReferenceType().name() was called without a null guard, making the entire audit log page fail to load.
Additional context
the issue has all the context