Bug 472617 - ITypeHierarchy#getSuperclass(IType) returns null for anonymous classes in LambdaExpressions
Summary: ITypeHierarchy#getSuperclass(IType) returns null for anonymous classes in Lam...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4.2   Edit
Hardware: PC Windows 8
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-14 09:06 EDT by Bastian U CLA
Modified: 2022-12-08 14:36 EST (History)
2 users (show)

See Also:


Attachments
Demo project (containing the visitor and logic to create the example project) (13.22 KB, application/x-zip-compressed)
2015-07-14 09:06 EDT, Bastian U CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bastian U CLA 2015-07-14 09:06:59 EDT
Created attachment 255183 [details]
Demo project (containing the visitor and logic to create the example project)

Example code:

public class T {
  public static void m() {
    new C() { };              // [1]
    Consumer<?> c = l -> {
      new C() { };            // [2]
    };
  }
}

class C { }


Applying following visitor to this example program allows to construct the type hierarchy of the anonymous class of "new C() { }":

class AnonymousClassVisitor extends ASTVisitor {
  public boolean visit(AnonymousClassDeclaration typeDeclaration) {
      IType type = (IType) typeDeclaration.resolveBinding().getJavaElement();
      ITypeHierarchy newSupertypeHierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
      IType superclass = newSupertypeHierarchy.getSuperclass(type);
      /* [3] */
 }
}

At [3], superclass is well initialized when handling the anonymous class declaration denoted with [1] (pointing to class C). It is, however null (!) when handling the declaration denoted with [2], occuring in a lambda expression.

The attachment contains demo code for this problem, providing logic to create the demo project in the runtime eclipse and applying the mentioned visitor.
Comment 1 Bastian U CLA 2015-07-15 06:51:34 EDT
(Might be related to #472714 ???)
Comment 2 Jay Arthanareeswaran CLA 2016-04-05 05:09:00 EDT
This might be related to anonymous type occurrence count. Will take a look during 4.7.
Comment 3 Manoj N Palat CLA 2018-05-21 06:06:52 EDT
Bulk move out of 4.8
Comment 4 Eclipse Genie CLA 2020-07-14 10:22:20 EDT
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 5 Eclipse Genie CLA 2022-12-08 14:36:18 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.