You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This class loader eventually gets passed to ScoreDirectorFactoryFactory::decideMultipleScoreDirectorFactories, but it is not passed to the ServiceLoader.load call on line 69 of ScoreDirectorFactoryFactory.java. That is, instead of using the provided class loader, it ends up using the default class loader. In my application, this does not work -- the provided class loader needs to be used.
Expected behavior
Uses the class loaded provided by the SolverConfig when loading services.
Actual behavior
Uses the default class loader when loading services. (Specifically, ServiceLoader defaults to Thread.currentThread().getContextClassLoader().)
To Reproduce
Reproducing my problem where the service loader fails requires access to the specific environment I'm working in, which is not possible. However, you can easily check which class loader is being used by setting a breakpoint and stepping in the ServiceLoader.load call on line 69 of ScoreDirectorFactoryFactory.java.
Environment
Timefold Solver Version or Git ref:
1.7.0
Output of java -version:
openjdk version "17.0.10" 2024-01-16
OpenJDK Runtime Environment Temurin-17.0.10+7 (build 17.0.10+7)
OpenJDK 64-Bit Server VM Temurin-17.0.10+7 (build 17.0.10+7, mixed mode, sharing)
Output of uname -a or ver:
OS Name Microsoft Windows 11 Pro
Version 10.0.22631 Build 22631
Additional information
The fix should be very simple, as the class loader is already passed as an argument to ScoreDirectorFactoryFactory::decideMultipleScoreDirectorFactories. Simply change:
Hello @marinier - PRs are welcome. Even if we eventually remove the service loader from constraint streams (as discussed here), it will still remain for enterprise edition, so this will still make sense.
Describe the bug
When creating a
SolverConfig
you can set a class loader on it like this:This class loader eventually gets passed to
ScoreDirectorFactoryFactory::decideMultipleScoreDirectorFactories
, but it is not passed to theServiceLoader.load
call on line 69 ofScoreDirectorFactoryFactory.java
. That is, instead of using the provided class loader, it ends up using the default class loader. In my application, this does not work -- the provided class loader needs to be used.Expected behavior
Uses the class loaded provided by the
SolverConfig
when loading services.Actual behavior
Uses the default class loader when loading services. (Specifically,
ServiceLoader
defaults toThread.currentThread().getContextClassLoader()
.)To Reproduce
Reproducing my problem where the service loader fails requires access to the specific environment I'm working in, which is not possible. However, you can easily check which class loader is being used by setting a breakpoint and stepping in the
ServiceLoader.load
call on line 69 ofScoreDirectorFactoryFactory.java
.Environment
Timefold Solver Version or Git ref:
1.7.0
Output of
java -version
:openjdk version "17.0.10" 2024-01-16
OpenJDK Runtime Environment Temurin-17.0.10+7 (build 17.0.10+7)
OpenJDK 64-Bit Server VM Temurin-17.0.10+7 (build 17.0.10+7, mixed mode, sharing)
Output of
uname -a
orver
:OS Name Microsoft Windows 11 Pro
Version 10.0.22631 Build 22631
Additional information
The fix should be very simple, as the class loader is already passed as an argument to
ScoreDirectorFactoryFactory::decideMultipleScoreDirectorFactories
. Simply change:to
I'm happy to provide a pull request if desired.
The text was updated successfully, but these errors were encountered: