Community
Participate
Working Groups
We're seeing occasional NPEs in jdt.ls, when calling GenerateToStringOperation. Here's the stacktrace: Caused by: java.lang.NullPointerException at org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.AbstractToStringGenerator.createMethodComment(AbstractToStringGenerator.java:232) at org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.AbstractToStringGenerator.complete(AbstractToStringGenerator.java:489) at org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.StringConcatenationGenerator.complete(StringConcatenationGenerator.java:93) at org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.AbstractToStringGenerator.generateToStringMethod(AbstractToStringGenerator.java:207) at org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.GenerateToStringOperation.run(GenerateToStringOperation.java:102) In some circumstances, ITypeBinding object= fAst.resolveWellKnownType("java.lang.Object"); returns null, leading to the latter NPE https://github.com/eclipse/eclipse.jdt.ui/blob/master/org.eclipse.jdt.core.manipulation/core%20extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/AbstractToStringGenerator.java#L231 I don't know how to reproduce the issue though, it happens infrequently. But simply adding a null-check in createMethodComment would suffice.
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/165809
Thanks Fred for putting a patch - moving this to jdt.ui as this code is in ui
fAst.resolveWellKnownType("java.lang.Object") should not return null in any case. Also, the NPE in the stack trace is at line 232, not at 231. "Show Revision Information" shows a change in Jan 2020 from bug 548309 at this location. Needs investigation.
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/165817
Is the stack trace from the description all of the JDT/platform code on the stack? If not please provide more stack frames, would be good to know what ran into the NPE.
(In reply to Noopur Gupta from comment #3) > fAst.resolveWellKnownType("java.lang.Object") should not return null in any > case. > right, ideally no, it should not return null and I would expect it to be a bug. In the rare case where this type is not accessible, then it could be a different issue. @Fred: by any rare chance, do you have any java.lang package other than the JRE java.lang package accessible from the project? - checking to eliminate that possibility.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.
The patch is already in place (namely that the equals() calls have the constants specified first.