Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential NullPointerException in UserContext by adding null check for parentContext. #4348

Merged
merged 4 commits into from
Aug 7, 2024

Conversation

mrkartik00
Copy link
Contributor

Title: [#4331] fix: add null check for parentContext in UserContext

What changes were proposed in this pull request?

This pull request adds a null check for the parentContext variable in the getUserContext method of UserContext.java. This ensures that a NullPointerException is avoided when deepCopy() is called on parentContext.

Why are the changes needed?

The change is needed to prevent a potential NullPointerException if parentContext is null. Adding this check makes the code more reliable.

Fix: #4331

Does this PR introduce any user-facing change?

No, this change does not introduce any user-facing changes.

How was this patch tested?

The change was reviewed to ensure that the null check effectively prevents the issue. No new tests were needed, as this is a preventive fix.

…k for parentContext.

Added a null check before calling deepCopy() on parentContext in the getUserContext method to prevent a possible NullPointerException. This ensures the robustness of the code when dealing with authentication contexts
@mrkartik00 mrkartik00 changed the title Fix potential NullPointerException in UserContext by adding null chec… Fix potential NullPointerException in UserContext by adding null check for parentContext. Aug 4, 2024
Copy link
Member

@justinmclean justinmclean left a comment

Choose a reason for hiding this comment

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

I would leave the existing comment as is and not remove it

@justinmclean
Copy link
Member

@mrkartik00 It looks like the comments have still been removed. Can you please add them back?

@justinmclean
Copy link
Member

Please remove the "// Improvement: Check if parentContext is not null before using it" there is no need for this comment in the code.

@@ -125,7 +125,7 @@ public static UserContext getUserContext(
} else if (authenticationType == AuthenticationType.KERBEROS) {
// if the kerberos authentication is inherited from the parent context, we will use the
// parent context's kerberos configuration.
if (authenticationConfig.isSimpleAuth()) {
if (parentContext != null && authenticationConfig.isSimpleAuth()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In fact, if the value of authenticationType is KERBEROS and authenticationConfig.isSimpleAuth() is true, the value of parentContext is not null. Anyway, adding a check won't make things worse.

@yuqi1129 yuqi1129 merged commit 4249993 into apache:main Aug 7, 2024
33 checks passed
github-actions bot pushed a commit that referenced this pull request Aug 7, 2024
…k for parentContext. (#4348)

Title: [#4331] fix: add null check for parentContext in UserContext

### What changes were proposed in this pull request?

This pull request adds a null check for the parentContext variable in
the getUserContext method of UserContext.java. This ensures that a
NullPointerException is avoided when deepCopy() is called on
parentContext.


### Why are the changes needed?

The change is needed to prevent a potential NullPointerException if
parentContext is null. Adding this check makes the code more reliable.

Fix: #4331 

### Does this PR introduce _any_ user-facing change?

No, this change does not introduce any user-facing changes.

### How was this patch tested?

The change was reviewed to ensure that the null check effectively
prevents the issue. No new tests were needed, as this is a preventive
fix.
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.

[Improvement] Possible null pointer in UserContext.java
3 participants