Skip to content

Commit

Permalink
Don't use SharedSecrets, but instead directly call a private constructor
Browse files Browse the repository at this point in the history
This solves the problem that SharedSecrets is found in different
packages across different Java versions, e.g.
- jdk.internal.access.SharedSecrets in OpenJDK 12+
- jdk.internal.misc.SharedSecrets in OpenJDK <12
- sun.misc.SharedSecrets in Oracle JDK 8
  • Loading branch information
muffato authored and ens-bwalts committed Feb 10, 2020
1 parent 551cc77 commit 6c6d939
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions wrappers/java/src/main/java/org/ensembl/hive/RunWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jdk.internal.access.SharedSecrets;

/**
* Main class for running a hive worker in Java
*
Expand Down Expand Up @@ -78,11 +76,11 @@ public static void main(String[] args) throws Exception {
Constructor<?> ctor = clazz.getConstructor();
// log.debug("Initializing runnable module " + clazz.getName() + " from " + args[1] + " and " + args[2]);

FileDescriptor inputDescriptor = new FileDescriptor();
SharedSecrets.getJavaIOFileDescriptorAccess().set(inputDescriptor, Integer.parseInt(args[1]));

FileDescriptor outputDescriptor = new FileDescriptor();
SharedSecrets.getJavaIOFileDescriptorAccess().set(outputDescriptor, Integer.parseInt(args[2]));
Constructor<FileDescriptor> fdctor = FileDescriptor.class.getDeclaredConstructor(Integer.TYPE);
fdctor.setAccessible(true);
FileDescriptor inputDescriptor = fdctor.newInstance(Integer.parseInt(args[1]));
FileDescriptor outputDescriptor = fdctor.newInstance(Integer.parseInt(args[2]));
fdctor.setAccessible(false);

BaseRunnable runnable = (BaseRunnable) (ctor.newInstance());
runnable.setFileDescriptors(inputDescriptor, outputDescriptor);
Expand Down
2 changes: 1 addition & 1 deletion wrappers/java/wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ elif [ "$action" == "run" ]; then

#echo "Running in $PWD:" java -cp "lib/*" org.ensembl.hive.RunWrapper "$module" "$fd_in" "$fd_out" "$debug"

exec java -cp target/eHive-*-jar-with-dependencies.jar --add-exports java.base/jdk.internal.access=ALL-UNNAMED org.ensembl.hive.RunWrapper "$module" "$fd_in" "$fd_out" "$debug"
exec java -cp target/eHive-*-jar-with-dependencies.jar --add-opens java.base/java.io=ALL-UNNAMED org.ensembl.hive.RunWrapper "$module" "$fd_in" "$fd_out" "$debug"
else
echo "Command-line error: No mode provided"
echo "$usage"
Expand Down

0 comments on commit 6c6d939

Please sign in to comment.