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

InternalError "Enclosing method not found" #18701

Closed
davidlar opened this issue Oct 16, 2023 · 9 comments · Fixed by #20558
Closed

InternalError "Enclosing method not found" #18701

davidlar opened this issue Oct 16, 2023 · 9 comments · Fixed by #20558
Assignees
Milestone

Comments

@davidlar
Copy link

We have a problem stopping us from updating to Scala 3, since we use Graalvm native-image. Native image uses a lot reflection when building and the byte code generated by Scala 3 seems to be invalid in some edge cases. For us the error happens in the skunk database library typelevel/skunk#623. I've finally been able to create a small reproducer, I think.
It breaks when Class.getEnclosingMethod() is called for the check() method below.

Compiler version

3.3.1

Minimized code

trait TA {
  def tb(): TB
}

trait TB {
  def check(): Unit
}

object A {
  def a(): TA = 
    new TA {
      override def tb(): TB =
        Seq(1).map { _ =>
          new TB {
            override def check(): Unit = 
              println(this.getClass.getEnclosingMethod()) // InternalError thrown here
          }
        }.head
    }
}


@main
def main() = {
  A.a().tb().check()
}

Output

InternalError

Expectation

The enclosing method should be returned

@davidlar davidlar added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 16, 2023
@bishabosha bishabosha added area:backend and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 16, 2023
@bishabosha
Copy link
Member

bishabosha commented Oct 16, 2023

in Scala 2.13.12 it will print public TB A$$anon$1.tb()

@davidlar
Copy link
Author

Yes sorry, the point was that it crashes in Scala 3. The print statement is useless and can be disregarded.

@bishabosha
Copy link
Member

Yes sorry, the point was that it crashes in Scala 3. The print statement is useless and can be disregarded.

No need to apologise, I was just adding extra context that indeed this is unexpected behaviour, because it works in 2.13

@davidlar
Copy link
Author

Is there any chance to get this fixed in the near future?

@bishabosha
Copy link
Member

@Gedochao

@davesmith00047
Copy link

Testing the issue authors code in 3.4.2, it builds fine but the error occurs at runtime. I have an example that fails with the same(?) error at the analysis phase.

[2/7] Performing analysis...  []                                                                    (9.9s @ 4.23GB)
  11,825 (94.11%) of 12,565 classes reachable
  20,108 (74.52%) of 26,982 fields reachable
  58,745 (81.93%) of 71,698 methods reachable
     249 classes,     0 fields, and     0 methods registered for reflection
       1 native library: -framework CoreServices

Fatal error: com.oracle.svm.core.util.VMError$HostedError: java.lang.InternalError: Enclosing method not found

@mbovel
Copy link
Member

mbovel commented Jun 10, 2024

This issue was picked for the Scala Issue Spree of tomorrow, June 11th. @dwijnand, @iusildra and @nmcb will be working on it. If you have any further insights into the issue or guidance on how to fix it, please leave it here.

@johnynek
Copy link

johnynek commented Nov 7, 2024

I've been trying to migrate to scala 3.5.2 and I'm hitting the same issue, however I have a somewhat large app (56kloc) and I haven't been able to see yet what is triggering the:

Fatal error: java.lang.InternalError: Enclosing method not found
	at java.base/java.lang.Class.getEnclosingMethod(Class.java:1296)

in native-image.

This app works fine in scala 2.13. Here is link to the CI failure:
https://github.com/johnynek/bosatsu/actions/runs/11711883088/job/32621374003?pr=1246

My guess is there are more variants of the problem that this issue was filed for, but I don't know how to get native-image to tell me where it is when it fails, and hunting through this rather large app seems a bit daunting.

@davidlar
Copy link
Author

davidlar commented Nov 7, 2024

In our case the bug happened in skunk and because of this we need a new release of skunk built on a fixed version of Scala 3. It doesn't help to upgrade our code to Scala 3.3.4/3.5.2, since the invalid byte code is in the skunk jar. We tried to build skunk ourselves with Scala 3.3.4 and then it works fine. Maybe you have something similar with another lib...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants