Skip to content

fix: handle DASHBOARD audit reference type to prevent NPE in audit log UI#16355

Open
moerradi wants to merge 1 commit intogravitee-io:masterfrom
moerradi:master
Open

fix: handle DASHBOARD audit reference type to prevent NPE in audit log UI#16355
moerradi wants to merge 1 commit intogravitee-io:masterfrom
moerradi:master

Conversation

@moerradi
Copy link
Copy Markdown

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

@moerradi moerradi requested a review from a team as a code owner April 13, 2026 08:22
…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.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

medium

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
  1. 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.
  2. Prioritize code simplicity and readability over micro-optimizations that do not address a real performance bottleneck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant