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
[WFCORE-5850] Null pointers should not be dereferenced (controller) #5012
[WFCORE-5850] Null pointers should not be dereferenced (controller) #5012
Conversation
Core - Full Integration Build 11326 outcome was FAILURE using a merge of 08bcff3 Failed tests
|
Core - Full Integration Build 11329 outcome was FAILURE using a merge of 08bcff3 Failed tests
|
OperationTransformerRegistry operationTransformerRegistry = get(value); | ||
if (operationTransformerRegistry != null) { | ||
operationTransformerRegistry.registerTransformer(iterator, operationName, entry); | ||
} |
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've reviewed the changes but I don't feel capable to approve them as they are. In general, they look harmless; we can argue that if the CI is passing, then we are fine, but there are possibilities for introducing an unexpected bug or a side effect.
I think we should be more cautious with those changes.
Specifically, this one, if operationTransformerRegistry
is null the old behavior was to get a null pointer exception, but now the method is silently invoked without registering the expected transformer and that can be a wrong result difficult to track and debug on a mixed domain scenario. Maybe it could be better to keep the NPE or throw an IAE if it is considered an invalid state. This argument can be also extrapolated to YamlConfigurationExtension.java, OperationValidator.java, in which case leaving the code as it is now is also a valid alternative.
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.
@yersan thanks for your feedback. I would provide an explicit exception here
if (operationTransformerRegistry == null) {
throw new IllegalStateException("No OperationTransformerRegistry found for " + value); //implemented in I18N style as logger
}
For the other ones, YamlConfigurationExtension andOperationValidator I'm going to ask Emmanuel as original author. All if/else avoid a null pointer, except the ones I have changed.
@@ -498,7 +498,9 @@ public void processOperation(ImmutableManagementResourceRegistration rootRegistr | |||
if (map != null && map.containsKey("index")) { | |||
op.get("index").set((Integer) map.get("index")); | |||
} | |||
op.get(VALUE).set(processObjectAttribute((ObjectTypeAttributeDefinition) type, map)); | |||
if (map != null) { | |||
op.get(VALUE).set(processObjectAttribute((ObjectTypeAttributeDefinition) type, map)); |
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.
@ehsavoie Could you please have a look at this fix? All other calls prevent a null pointer deref, except this one. Is it intended to break here?
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 think the null check used to be before the check from the index initially
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.
@ehsavoie I'm still in doubt, are you fine with this change then?
@@ -130,6 +130,7 @@ public void validateOperation(final ModelNode operation) { | |||
OperationEntry entry = root.getOperationEntry(address, name); | |||
if (entry == null) { | |||
throwOrWarnAboutDescriptorProblem(ControllerLogger.ROOT_LOGGER.noOperationEntry(name, address)); | |||
return; // in case of warning no further processing possible (entry causes NullPointer) |
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.
@kabir Could you have a look at this fix, please? Many other points in the code have the pattern
throwOrWarnAboutDescriptorProblem(ControllerLogger....);
return;
Here the return;
is missing. Is it intended to break later with an NPE in case of logging a warning?
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.
@boris-unckel I think it looks fine. A lot of this is cruft from ancient times before we became a lot stricter about needing definitions for everything
08bcff3
to
abebf08
Compare
Core - Full Integration Build 11493 outcome was FAILURE using a merge of abebf08 Failed tests
|
@yersan The changes requested are present or clarified with the original authors. Test failures seem unrelated. Could you have a final look at this, please? |
@@ -1028,7 +1029,7 @@ public Resource createResource(PathAddress relativeAddress) { | |||
} | |||
|
|||
private Resource createResourceInternal(PathAddress relativeAddress, int index) throws UnsupportedOperationException { | |||
ImmutableManagementResourceRegistration current = getResourceRegistration(); | |||
ImmutableManagementResourceRegistration current = checkNotNullParamWithNullPointerException("getResourceRegistration", getResourceRegistration()); |
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.
Sorry for the back-and-forth @boris-unckel , I missed this one; the purpose of checkNotNullParamWithNullPointerException
is to check method params, so I would say we should not use it for any kind of situation. If you still want to avoid deferring the NPE here, we could use a specific logger entry for this one.
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.
@yersan NP, thanks for the additional feedback. I have changed accordingly.
@@ -498,7 +498,9 @@ public void processOperation(ImmutableManagementResourceRegistration rootRegistr | |||
if (map != null && map.containsKey("index")) { | |||
op.get("index").set((Integer) map.get("index")); | |||
} | |||
op.get(VALUE).set(processObjectAttribute((ObjectTypeAttributeDefinition) type, map)); | |||
if (map != null) { | |||
op.get(VALUE).set(processObjectAttribute((ObjectTypeAttributeDefinition) type, map)); |
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.
@ehsavoie I'm still in doubt, are you fine with this change then?
abebf08
to
dc59a29
Compare
Core - Full Integration Build 11373 outcome was FAILURE using a merge of dc59a29 Failed tests
|
Core - Full Integration Build 11505 outcome was FAILURE using a merge of dc59a29 Failed tests
|
There has been no activity on this PR for 45 days. It will be auto-closed after 90 days. |
There has been no activity on this PR for 90 days and it has been closed automatically. |
Fixes https://issues.redhat.com/browse/WFCORE-5850