Bug 472714 - ITypeHierarchy#getSuperclass(IType) returns null for anonymous classes at any place after one in a Lambda Expression has been encountered
Summary: ITypeHierarchy#getSuperclass(IType) returns null for anonymous classes at any...
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-15 06:51 EDT by Bastian U CLA
Modified: 2022-11-04 19:59 EDT (History)
2 users (show)

See Also:


Attachments
Demo project (containing the visitor and logic to create the example project) (5.80 KB, application/x-zip-compressed)
2015-07-15 06:51 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-15 06:51:02 EDT
Created attachment 255207 [details]
Demo project (containing the visitor and logic to create the example project)

(Might be related to #472617 ???)

Example code: 

public class R2 {
  void l() {
    C c1 = new C();
    c1.a(a -> {
      new Object() { };                   // [1]
    });
    C c2 = new C();
    c2.a(new Consumer<Object>() {         // [2]
      @Override
      public void accept(Object t) {
      }
    });
  }
}

class C {
  void a(Consumer<?> d) {
  }
}


Applying following visitor to this example program allows to construct the type hierarchy of the anonymous class of "new Consumer<Object>() { ... }":

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 null, when handling the anonymous class declaration denoted with [2].

The strange thing is that it is only null, if the anonymous class declaration denoted with [1] is handled before. If you remove line [1] or only remove the curly braces (so that 'new C(){};' becomes 'new C();'), superclass at [3] is  well 'java.lang.Object' when handling [2]. 


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 Jay Arthanareeswaran CLA 2016-04-05 05:09:23 EDT
This might be related to anonymous type occurrence count. Will take a look during 4.7.
Comment 2 Manoj N Palat CLA 2018-05-21 06:07:05 EDT
Bulk move out of 4.8
Comment 3 Eclipse Genie CLA 2020-08-21 06:53:10 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 4 Eclipse Genie CLA 2022-11-04 19:59:41 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.