From 9d16b91027f2691949328b029bfceb58cddc92c9 Mon Sep 17 00:00:00 2001 From: Guoxiong Li Date: Fri, 10 Jun 2022 03:30:22 +0800 Subject: [PATCH] [fix][client] Fix JDK17 compatibility issue (#15964) Fixes #15349 ### Motivation When using the JDK17, pulsar-client throws exception `module java.base does not export sun.net to unnamed module`, it is good to fix it. ### Modifications Add `--add-opens java.base/sun.net=ALL-UNNAMED` to java option when using JDK17. ### Verifying this change - [x] Make sure that the change passes the CI checks. ### Documentation Check the box below or label this PR directly. Need to update docs? - [x] `doc-not-needed` --- bin/pulsar-client | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/pulsar-client b/bin/pulsar-client index 73f82df37b06b..acdc262a1e239 100755 --- a/bin/pulsar-client +++ b/bin/pulsar-client @@ -94,6 +94,13 @@ PULSAR_CLASSPATH="`dirname $PULSAR_LOG_CONF`:$PULSAR_CLASSPATH" OPTS="$OPTS -Dlog4j.configurationFile=`basename $PULSAR_LOG_CONF`" OPTS="$OPTS -Djava.net.preferIPv4Stack=true" +IS_JAVA_8=`$JAVA -version 2>&1 |grep version|grep '"1\.8'` +# Start --add-opens options +# '--add-opens' option is not supported in jdk8 +if [[ -z "$IS_JAVA_8" ]]; then + OPTS="$OPTS --add-opens java.base/sun.net=ALL-UNNAMED" +fi + OPTS="-cp $PULSAR_CLASSPATH $OPTS" OPTS="$OPTS $PULSAR_EXTRA_OPTS"