Bug 563357 - NullPointerException in AbstractToStringGenerator.createMethodComment
Summary: NullPointerException in AbstractToStringGenerator.createMethodComment
Status: CLOSED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.15   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 4.24   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: investigate, needinfo
Depends on:
Blocks:
 
Reported: 2020-05-19 12:51 EDT by Fred Bricon CLA
Modified: 2022-12-13 10:44 EST (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fred Bricon CLA 2020-05-19 12:51:39 EDT
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.
Comment 1 Eclipse Genie CLA 2020-07-03 12:19:46 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/165809
Comment 2 Manoj N Palat CLA 2020-07-04 00:22:46 EDT
Thanks Fred for putting a patch - moving this to jdt.ui as this code is in ui
Comment 3 Noopur Gupta CLA 2020-07-04 03:49:39 EDT
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.
Comment 4 Eclipse Genie CLA 2020-07-04 04:34:38 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/165817
Comment 5 Simeon Andreev CLA 2020-07-04 05:18:02 EDT
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.
Comment 6 Manoj N Palat CLA 2020-07-06 01:59:42 EDT
(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.
Comment 7 Eclipse Genie CLA 2022-12-09 18:52:59 EST
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.
Comment 8 Jeff Johnston CLA 2022-12-13 10:44:44 EST
The patch is already in place (namely that the equals() calls have the constants specified first.