Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IncompatibleClassChangeError on getDeclaringClass #7994

Closed
scabug opened this issue Nov 22, 2013 · 11 comments
Closed

IncompatibleClassChangeError on getDeclaringClass #7994

scabug opened this issue Nov 22, 2013 · 11 comments

Comments

@scabug
Copy link

scabug commented Nov 22, 2013

Executing this simple snippet of code:

object Test {
  def main(args: Array[String]): Unit = {
    val outter = new MyTest {
      val inner = new MyTest {
      }
    }
  }
}

class MyTest {
  println(s"${getClass.getName} - ${getClass.getDeclaringClass}")
}

Results in:

java.lang.IncompatibleClassChangeError: Test$ and Test$$anon$1$$anon$2 disagree on InnerClasses attribute
java.lang.IncompatibleClassChangeError: Test$ and Test$$anon$1$$anon$2 disagree on InnerClasses attribute
	at java.lang.Class.getDeclaringClass0(Native Method)
	at java.lang.Class.getDeclaringClass(Class.java:1101)
@scabug
Copy link
Author

scabug commented Nov 22, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7994?orig=1
Reporter: Matt Hicks (darkfrog)
Affected Versions: 2.10.3
Attachments:

  • Test2.scala (created on Nov 22, 2013 2:12:28 PM UTC, 220 bytes)

@scabug
Copy link
Author

scabug commented Dec 3, 2013

Matt Hicks (darkfrog) said:
How long does it take to get anyone to verify this bug?

@scabug
Copy link
Author

scabug commented Dec 3, 2013

@som-snytt said:
I can verify that I get the same result. So, about 32 minutes. I guess for pizza, that means it's free.

@scabug
Copy link
Author

scabug commented Dec 4, 2013

Matt Hicks (darkfrog) said:
I appreciate the follow-up but it's been nearly two weeks since I first reported it, so that's a pretty stale pizza. ;)

@scabug scabug added the backend label Apr 7, 2017
@SethTisue
Copy link
Member

closing backend tickets which are likely stale; comment and/or reopen if you have evidence this is still applicable

@lrytz
Copy link
Member

lrytz commented Mar 2, 2018

Fixed, the 2.12 backend got an onvehaul of InnerClass attribute computation. Let's verify the result is correct and add a regression test to https://github.com/scala/scala/tree/v2.13.0-M3/test/files/jvm/innerClassAttribute

@lrytz lrytz reopened this Mar 2, 2018
@lrytz lrytz added this to the 2.12.6 milestone Mar 2, 2018
@SethTisue SethTisue modified the milestones: 2.12.6, 2.12.7 Mar 23, 2018
@adriaanm
Copy link
Contributor

@lrytz did this end up getting verified as fixed?

@adriaanm
Copy link
Contributor

It doesn't crash, at least. I'll leave it open in case null was not the expected result for the declaring class..

scala-2.12.7-bin-f2129b9/bin/scala ~/Library/Preferences/IdeaIC2018.2/scratches/scratch_7.scala
Main$$anon$1 - null
Main$$anon$1$$anon$2 - null

@adriaanm adriaanm modified the milestones: 2.12.7, 2.12.8, Backlog Sep 18, 2018
@jxnu-liguobin
Copy link
Member

Empty seems wrong? I am ready to look at the issue, where are the relevant codes or files? thanks

@lrytz
Copy link
Member

lrytz commented Mar 25, 2021

https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Class.html#getDeclaringClass() says

If the class or interface represented by this Class object is a member of another class, returns the Class object representing the class in which it was declared

The two anonymous classes are both not "member" classes, so null is the correct value.

https://github.com/scala/scala/blob/8a2cf63ee5bad8c8c054f76464de0e10226516a0/src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala#L352-L353

@jxnu-liguobin you could add a test case, that would be welcome.

Just tested with Java, it does the same:

public class Test {
  public static void main(String[] args) {
    Object o = new MyTest() {
      Object i = new MyTest() { };
    };
  }
}

class MyTest {
  public MyTest() {
    System.out.println(this.getClass().getName());
    System.out.println(this.getClass().getDeclaringClass());
  }
}
Test$1
null
Test$1$1
null

jxnu-liguobin added a commit to jxnu-liguobin/scala that referenced this issue Mar 25, 2021
@jxnu-liguobin
Copy link
Member

jxnu-liguobin commented Mar 25, 2021

@lrytz
ok, https://github.com/scala/scala/pull/9553/files, i have added scala test case

lrytz added a commit to scala/scala that referenced this issue Mar 25, 2021
@lrytz lrytz closed this as completed Mar 25, 2021
@SethTisue SethTisue removed this from the Backlog milestone Mar 25, 2021
@dwijnand dwijnand added this to the 2.13.6 milestone Apr 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants