homberghp commented on PR #8575: URL: https://github.com/apache/netbeans/pull/8575#issuecomment-2965433633
> I am sorry, but this is not right. I don't think the leaf can be `null`, by construction. The (future) `leaf` is always dereferenced by the `TreePath` constructor: https://github.com/openjdk/jdk/blob/3b32f6a8ec37338764d3e6713247ff96e49bf5b3/src/jdk.compiler/share/classes/com/sun/source/util/TreePath.java#L118 > > `TreePath.getParentPath()` may return `null`, and that will be the culprit here. I think there should be a test for `tp == null`, and probably `return null;`. Testcase is: > > ``` > public void testStandaloneReturn() throws Exception { > HintTest.create() > .input(""" > package test; > public class Test { > } > return; > """, > false) > .run(RemoveUnnecessary.class) > .assertWarnings(); > } > ``` Your test points exactly at the culprit, it becomes red, the true colour of a useful test, when I comment the solution out. So your solution (and added test) it is. Thanks mbien and lahodaj. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org For additional commands, e-mail: notifications-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists