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 committed Feb 10, 2020
1 parent 4d4689e commit 50f5fdd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 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;

import org.ensembl.hive.Utils;

/**
Expand Down Expand Up @@ -70,10 +68,11 @@ public static void main(String[] args) throws Exception {

BaseRunnable runnable = Utils.findRunnable(args[0]);

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);
runnable.setFileDescriptors(inputDescriptor, outputDescriptor);

runnable.processLifeCycle();
Expand Down
2 changes: 1 addition & 1 deletion wrappers/java/wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ elif [ "$action" == "run" ]; then
exit 1
fi

exec java -cp "$jar" --add-exports java.base/jdk.internal.access=ALL-UNNAMED org.ensembl.hive.RunWrapper "$module" "$fd_in" "$fd_out" "$debug"
exec java -cp "$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"
Expand Down

0 comments on commit 50f5fdd

Please sign in to comment.