Skip to content

Fixes scala-reflect issue with GitHub pureconfig (https://github.com/opalj/JCG/issues/17)#362

Merged
errt merged 4 commits into
developfrom
fix/scala-reflect-issue-with-github-pureconfig
May 12, 2026
Merged

Fixes scala-reflect issue with GitHub pureconfig (https://github.com/opalj/JCG/issues/17)#362
errt merged 4 commits into
developfrom
fix/scala-reflect-issue-with-github-pureconfig

Conversation

@svenkeidel
Copy link
Copy Markdown
Collaborator

Hi,

This fixes opalj/JCG#17.

The issue is that Opal depends on scala-reflect, which is binary incompatible with Scala 3 classes.
The problem is that Githubs pureconfig generates Scala 3 code that crashes scala-reflect searches for ConfigurationEntryPointsFinder.

The fix reimplements the ConfigurationEntryPointsFinder.EntryPointContainer configuration reader to avoid the generation of problematic Scala 3 classes.

I tested the fix in JCG and it works.

Sven

@errt
Copy link
Copy Markdown
Collaborator

errt commented May 12, 2026

/it:test

// Implement ConfigReader manually to avoid issue with scala-reflect: https://github.com/opalj/JCG/issues/17
implicit private val entryPointContainerReader: ConfigReader[EntryPointContainer] =
ConfigReader.forProduct3("declaring-class", "name", "descriptor")(EntryPointContainer.apply)
.orElse(ConfigReader.forProduct3("declaringClass", "name", "descriptor")(EntryPointContainer.apply))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this? There should only be one way to write the keys that is valid now.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • reference.conf uses "declaring-class":

    {declaring-class = "java/lang/System", name = "initializeSystemClass", descriptor = "()V"},
    {declaring-class = "java/lang/Thread", name = "<init>", descriptor = "(Ljava/lang/ThreadGroup;Ljava/lang/Runnable;)V"},
    {declaring-class = "java/lang/Thread", name = "<init>", descriptor = "(Ljava/lang/ThreadGroup;Ljava/lang/String;)V"},
    {declaring-class = "java/lang/ThreadGroup", name = "<init>", descriptor = "()V"},
    {declaring-class = "java/lang/Thread", name = "exit", descriptor = "()V"},
    {declaring-class = "java/lang/ThreadGroup", name = "uncaughtException", descriptor = "(Ljava/lang/Thread;Ljava/lang/Throwable;)V"},
    {declaring-class = "java/lang/ref/Reference$ReferenceHandler", name = "run", descriptor = "()V"},
    {declaring-class = "java/lang/ClassLoader", name = " <init>", descriptor = "()V"},
    {declaring-class = "java/lang/ClassLoader", name = "loadClassInternal", descriptor = "(Ljava/lang/String;)Ljava/lang/Class;"},
    {declaring-class = "java/lang/ClassLoader", name = "checkPackageAccess", descriptor = "(Ljava/lang/Class;Ljava/security/ProtectionDomain;)V"},
    {declaring-class = "java/lang/ClassLoader", name = "addClass", descriptor = "(Ljava/lang/Class;)V"},
    {declaring-class = "java/lang/ClassLoader", name = "findNative", descriptor = "(Ljava/lang/ClassLoader;Ljava/lang/String;)J"},
    {declaring-class = "java/security/PrivilegedActionException", name = "<init>", descriptor = "(Ljava/lang/Exception;)V"},
    {declaring-class = "java/lang/System", name = "initPhase1", descriptor = "()V"},
    {declaring-class = "java/lang/System", name = "initPhase2", descriptor = "(ZZ)I"}
    {declaring-class = "java/lang/System", name = "initPhase3", descriptor = "()V"}

  • org.opalj.br.analyses.cg.InitialEntryPointsKey.entryPoints uses "declaringClass": https://github.com/opalj/JCG/blob/master/jcg_opal_testadapter/src/main/scala/OpalJCGAdatper.scala#L82-L83

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter is because JCG has not been updated to recent Scala-3 based OPAL which, due to changes in the config library, had to change to "declaring-class". I.e., I think JCG has to be changed here instead of supporting different keys in OPAL.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation uses "declaringClass" too:

* {{{
* org.opalj.br.analyses.cg {
* InitialEntryPointKey {
* analysis = "org.opalj.br.analyses.cg.ConfigurationEntryPointsFinder"
* entryPoints = [
* {declaringClass = "java/util/List+", name = "add"},
* {declaringClass = "java/util/List", name = "remove", descriptor = "(I)Z"}
* ]
* }
* }
* }}}

Probably should be updated as well.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely. Want to do that in this PR?

@svenkeidel
Copy link
Copy Markdown
Collaborator Author

Done.

Copy link
Copy Markdown
Collaborator

@errt errt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@errt errt added this pull request to the merge queue May 12, 2026
Merged via the queue into develop with commit 8870593 May 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants