eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
158 stars 126 forks source link

NPE in SourceTypeBinding.resolveTypesFor #318

Closed jukzi closed 10 months ago

jukzi commented 2 years ago

Internal Error

java.lang.NullPointerException: Cannot invoke "org.eclipse.jdt.internal.compiler.lookup.ClassScope.problemReporter()" because "this.scope" is null
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesFor(SourceTypeBinding.java:2702)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.getMethods(SourceTypeBinding.java:1913)
    at org.eclipse.jdt.internal.core.search.matching.MatchLocator.getMethodBinding(MatchLocator.java:1161)
    at org.eclipse.jdt.internal.core.search.matching.MatchLocator.getMethodBinding0(MatchLocator.java:1141)
    at org.eclipse.jdt.internal.core.search.matching.MatchLocator.getMethodBinding(MatchLocator.java:972)
    at org.eclipse.jdt.internal.core.search.matching.MethodLocator.matchMethod(MethodLocator.java:357)
    at org.eclipse.jdt.internal.core.search.matching.MethodLocator.resolveLevel(MethodLocator.java:749)
    at org.eclipse.jdt.internal.core.search.matching.ClassFileMatchLocator.locateMatches(ClassFileMatchLocator.java:270)
    at org.eclipse.jdt.internal.core.search.matching.MatchLocator.process(MatchLocator.java:1984)
    at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1353)
    at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1390)
    at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1532)
    at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:135)
    at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:251)
    at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:602)
    at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:670)
    at org.eclipse.jdt.internal.corext.callhierarchy.CallerMethodWrapper.findChildren(CallerMethodWrapper.java:155)
    at org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper.performSearch(MethodWrapper.java:266)
    at org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper.doFindChildren(MethodWrapper.java:197)
    at org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper.getCalls(MethodWrapper.java:88)
    at org.eclipse.jdt.internal.ui.callhierarchy.DeferredMethodWrapper.getCalls(DeferredMethodWrapper.java:70)
    at org.eclipse.jdt.internal.ui.callhierarchy.DeferredMethodWrapper.fetchDeferredChildren(DeferredMethodWrapper.java:78)
    at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:219)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

I see org.eclipse.jdt.internal.compiler.lookup.Scope.enclosingSourceType() can return null so org.eclipse.jdt.internal.compiler.lookup.BlockScope.addLocalType(TypeDeclaration) can create create a SourceTypeBinding with null scope image you might also want to add a Objects.requireNonNull to the constructor of SourceTypeBinding to get an eager fail.

jukzi commented 2 years ago

btw it happend when i tried to get call hierarchy for org.apache.commons.configuration.AbstractFileConfiguration.load(URL) image

stephan-herrmann commented 2 years ago

I see org.eclipse.jdt.internal.compiler.lookup.Scope.enclosingSourceType() can return null

Under one of these conditions:

so org.eclipse.jdt.internal.compiler.lookup.BlockScope.addLocalType(TypeDeclaration) can create create a SourceTypeBinding with null scope

Where did you see a null scope? I thought you were speaking of a non-null scope with a null SourceTypeBinding as its enclosing.

you might also want to add a Objects.requireNonNull to the constructor of SourceTypeBinding to get an eager fail.

You mean smth like:

public SourceTypeBinding(char[][] compoundName, PackageBinding fPackage, ClassScope scope) {
    Objects.requireNonNull(scope);

Not needed, it would already blow up three lines later:

    this.fileName = scope.referenceCompilationUnit().getFileName();
stephan-herrmann commented 2 years ago

If you're able to reproduce, can you call out the offending SourceTypeBinding and method?

stephan-herrmann commented 2 years ago

you might also want to add a Objects.requireNonNull to the constructor of SourceTypeBinding to get an eager fail.

If this was a comment to the original exception, then you might be interested actually in org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.cleanUp() :(

jukzi commented 10 months ago

i am closing this issue, because i don't know how to reproduce and never had a problem with this error again