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

Build Bug: org.apache.pekko.dispatch.PekkoJdk9ForkJoinPool is not on the classpath #1729

Open
He-Pin opened this issue Jan 18, 2025 · 11 comments
Labels
bug Something isn't working build sbt or build of the project
Milestone

Comments

@He-Pin
Copy link
Member

He-Pin commented Jan 18, 2025

Even the PekkoJdk9ForkJoinPool is on the final result jar, but it does not on the classpath.

How to reproduce:

  1. using Java 21
  2. sbt console
Welcome to Scala 2.13.16 (Java HotSpot(TM) 64-Bit Server VM, Java 21.0.5).

scala> classOf[org.apache.pekko.dispatch.PekkoJdk9ForkJoinPool]
                                         ^
       error: type PekkoJdk9ForkJoinPool is not a member of package org.apache.pekko.dispatch

scala> 

I think that's maybe caused by of the Jdk9.scala

@He-Pin He-Pin added bug Something isn't working build sbt or build of the project labels Jan 18, 2025
@He-Pin He-Pin added this to the 1.2.0 milestone Jan 18, 2025
@pjfanning
Copy link
Contributor

Existing workaround:

private def pekkoJdk9ForkJoinPoolClassOpt: Option[Class[_]] =
Try(Class.forName("org.apache.pekko.dispatch.PekkoJdk9ForkJoinPool")).toOption
private lazy val pekkoJdk9ForkJoinPoolHandleOpt: Option[MethodHandle] = {
if (JavaVersion.majorVersion == 8) {
None
} else {
pekkoJdk9ForkJoinPoolClassOpt.map { clz =>
val methodHandleLookup = MethodHandles.lookup()
val mt = MethodType.methodType(classOf[Unit], classOf[Int],
classOf[ForkJoinPool.ForkJoinWorkerThreadFactory],
classOf[Int], classOf[Thread.UncaughtExceptionHandler], classOf[Boolean])
methodHandleLookup.findConstructor(clz, mt)
}
}
}

@raboof
Copy link
Member

raboof commented Jan 18, 2025

The classpath of which module are you referring to?

If this is about actor-tests, perhaps you could use a similar technique as at https://github.com/apache/pekko/blob/main/build.sbt#L419 at https://github.com/apache/pekko/blob/main/build.sbt#L128

@He-Pin
Copy link
Member Author

He-Pin commented Jan 18, 2025

  1. Start SBT shell with Java 21/23
  2. type console
  3. classOf[org.apache.pekko.dispatch.PekkoJdk9ForkJoinPool, class not found.

OR:
When Run a TestJdk9 / testOnly $someJDK21Test on Java 21, and in $someJDK21Test use Class.forName("org.apache.pekko.dispatch.PekkoJdk9ForkJoinPool") , then a ClassNotFoundException throws.

@He-Pin
Copy link
Member Author

He-Pin commented Jan 18, 2025

I see no integration test for org.apache.pekko.dispatch.PekkoJdk9ForkJoinPool, which must been tested manually.
as the full classpath has no org.apache.pekko.dispatch.PekkoJdk9ForkJoinPool classes, just the product jar, where is the integration test for it @pjfanning ? shouldn't we expect a test for that lives in the scala-jdk9-only folder?

@He-Pin
Copy link
Member Author

He-Pin commented Jan 18, 2025

@pjfanning It's not I don't know how to write the code, but with the current setup, it can't be integrated tested, if you add an integration test for org.apache.pekko.dispatch.PekkoJdk9ForkJoinPool and show it works, I'm very happy to follow.

@raboof
Copy link
Member

raboof commented Jan 19, 2025

  1. Start SBT shell with Java 21/23

    1. type console

    2. classOf[org.apache.pekko.dispatch.PekkoJdk9ForkJoinPool, class not found.

classOf is a little weird, but testing with Class.forName("org.apache.pekko.dispatch.PekkoJdk9ForkJoinPool"):

indeed the root project does not depend on the individual modules, so that doesn't have PekkoJdk9ForkJoinPool or any other classes on the path.

actor / CompileJdk9 / console does find it, but indeed actor-tests / Test / console does not.

But with the following change to build.sbt:

 lazy val actorTests = pekkoModule("actor-tests")
   .configs(Jdk9.TestJdk9)
-  .dependsOn(testkit % "compile->compile;test->test", actor)
+  .dependsOn(
+    actor % "compile->CompileJdk9;test->test",
+    testkit % "compile->compile;test->test"
+  )

... it should work like I think you expect.

@He-Pin
Copy link
Member Author

He-Pin commented Jan 19, 2025

Doesn't work too :(

@raboof
Copy link
Member

raboof commented Jan 19, 2025

Interesting! In what way does it not work? How are you testing?

@He-Pin
Copy link
Member Author

He-Pin commented Jan 19, 2025

with sbt console and java 21

I think it's because the result class is not been added to the class path.

@raboof
Copy link
Member

raboof commented Jan 19, 2025

with sbt console and java 21

Hmm, that seems to work for me though.

What if you check out https://github.com/raboof/pekko/pull/new/actor-tests-depend-on-jdk9-classes

and then start sbt like this:

$ sbt
[info] welcome to sbt 1.10.7 (N/A Java 21.0.5)
[info] loading global plugins from /home/aengelen/.sbt/1.0/plugins
[info] loading settings for project cell-build from plugins.sbt...
[info] loading project definition from /cell/project
[info] loading settings for project pekko from build.sbt...
[info] resolving key references (70718 settings) ...
[info] Scala 2 optimizer/inliner enabled, to disable set the pekko.no.inline system property
(...)
pekko > actor-tests / Test / console
(...)
scala> Class.forName("org.apache.pekko.dispatch.PekkoJdk9ForkJoinPool")
val res0: Class[_] = class org.apache.pekko.dispatch.PekkoJdk9ForkJoinPool

do you get a different result?

@pjfanning
Copy link
Contributor

pjfanning commented Jan 19, 2025

The problem seems to happen when using submodules in this repo. If you use a project with a dependency on a pekko-actor snapshot jar or released jar, the class is there and is used if use Java version 11 up. The code is integration tested by our other modules like pekko-http. It would be nice if it was easier to test.

@pjfanning pjfanning modified the milestones: 1.2.0-M1, 1.2.0-M2, 1.2.0 Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working build sbt or build of the project
Projects
None yet
Development

No branches or pull requests

3 participants