-
Notifications
You must be signed in to change notification settings - Fork 392
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
Conversation
…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
There was a problem hiding this 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
...log-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/authentication/UserContext.java
Outdated
Show resolved
Hide resolved
@mrkartik00 It looks like the comments have still been removed. Can you please add them back? |
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()) { |
There was a problem hiding this comment.
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.
…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.
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.