Skip to content

fix: fixing null pointer exception error#1709

Open
Ayushman-Gaur wants to merge 4 commits intoopen-feature:mainfrom
Ayushman-Gaur:fixing-null-error
Open

fix: fixing null pointer exception error#1709
Ayushman-Gaur wants to merge 4 commits intoopen-feature:mainfrom
Ayushman-Gaur:fixing-null-error

Conversation

@Ayushman-Gaur
Copy link

@Ayushman-Gaur Ayushman-Gaur commented Mar 6, 2026

fix: null pointer exceptionn error

  • Adds null check for flag.getMetadata() in getFlagMetadata() to prevent
    NullPointerException when a flagd server doesn't support metadata.

Related Issues

Fixes #1708

Notes

currentFlagSetMetadata is always initialized as a new HashMap so it won't
be null, but flag.getMetadata() can return null on servers that don't support
metadata. Added a null guard before iterating over it.

How to test

A new test resolveBooleanValue_flagWithNullMetadata_doesNotThrowNPE has been
added to FlagdCoreTest that verifies no NPE is thrown when evaluating a flag
with no metadata defined.

@Ayushman-Gaur Ayushman-Gaur requested a review from a team as a code owner March 6, 2026 06:04
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a potential NullPointerException in the FlagdCore component by introducing a defensive null check when accessing flag metadata. It ensures the application remains robust even when flagd servers do not supply metadata, preventing crashes and improving stability. A new test case has been added to confirm the effectiveness of this fix.

Highlights

  • Null Pointer Exception Fix: Implemented a null check for flag.getTargeting() within the getFlagMetadata() method to prevent NullPointerException when a flagd server does not provide metadata.
  • New Test Case: Added resolveBooleanValue_flagWithNullMetadata_doesNotThrowNPE to FlagdCoreTest to validate that no NullPointerException is thrown when evaluating a flag with undefined metadata.
Changelog
  • tools/flagd-core/src/main/java/dev/openfeature/contrib/tools/flagd/core/FlagdCore.java
    • Added a null check for flag.getTargeting() before iterating over flag metadata to prevent NullPointerException.
  • tools/flagd-core/src/test/java/dev/openfeature/contrib/tools/flagd/core/FlagdCoreTest.java
    • Imported assertThatNoException from AssertJ.
    • Added a new test method resolveBooleanValue_flagWithNullMetadata_doesNotThrowNPE to verify that evaluating a flag with null metadata does not throw an exception.
Activity
  • The author, Ayushman-Gaur, identified and fixed a NullPointerException related to flag.getMetadata() when flagd servers do not support metadata.
  • A new test case, resolveBooleanValue_flagWithNullMetadata_doesNotThrowNPE, was added to FlagdCoreTest to demonstrate the fix and prevent regressions.
  • The PR description provides detailed notes on the issue and instructions on how to test the changes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
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 aims to fix a potential NullPointerException by adding a null check when accessing flag metadata, and includes a new test case to verify the fix. While the intention is good, the implementation of the fix in FlagdCore.java appears to be incorrect. The added condition flag.getTargeting() != null is effectively a no-op, as the getTargeting() method never returns null. I have provided a suggestion to correct the implementation to align with the stated goal of the pull request.

Signed-off-by: Ayushman Gaur <ayushmangaur2017@gmail.com>
Signed-off-by: Ayushman Gaur <ayushmangaur2017@gmail.com>
@Ayushman-Gaur Ayushman-Gaur changed the title fixing null pointer exception error fix: fixing null pointer exception error Mar 6, 2026
@Ayushman-Gaur
Copy link
Author

The CI failure is in the go-feature-flag provider which is unrelated to my changes in flagd-core. This appears to be a pre-existing issue.

@@ -273,7 +273,7 @@ private static ImmutableMetadata getFlagMetadata(Map<String, Object> currentFlag
Copy link
Contributor

Choose a reason for hiding this comment

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

You should also guard the for loop against currentFlagSetMetadata being null.

Signed-off-by: Ayushman Gaur <ayushmangaur2017@gmail.com>
Copy link
Contributor

@cupofcat cupofcat left a comment

Choose a reason for hiding this comment

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

Please solve the CI error with formatting too. Thanks for the contribution!

Signed-off-by: Ayushman Gaur <ayushmangaur2017@gmail.com>
@chrfwow chrfwow enabled auto-merge (squash) March 10, 2026 12:35
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.

[flagd] [BUG] Null Pointer Dereference in getFlagMetadata()

4 participants