fix(dist): start server with java 11 by imbajin · Pull Request #2020 · apache/hugegraph

@imbajin

fixed #1957

  1. use a better way to get the java version
  2. don't use float in shell directly (refer https://github.com/koalaman/shellcheck/wiki/SC2072)
    image
  3. we shall use shell-check plugin to avoid these problems (improvement)

@imbajin

@codecov

@javeme

java11 ci error:

Error: -18 12:24:06 [main] [ERROR] c.b.h.d.HugeGraphServer - HugeRestServer start error: 
java.lang.ExceptionInInitializerError: null
	at java.lang.Class.forName0(Native Method) ~[?:?]
	at java.lang.Class.forName(Class.java:315) ~[?:?]
	at org.apache.tinkerpop.gremlin.structure.util.GraphFactory.open(GraphFactory.java:63) ~[gremlin-core-3.5.1.jar:3.5.1]
	at com.baidu.hugegraph.auth.StandardAuthenticator.setup(StandardAuthenticator.java:131) ~[hugegraph-api-0.13.0.jar:0.69.0.0]
	at com.baidu.hugegraph.auth.HugeAuthenticator.loadAuthenticator(HugeAuthenticator.java:146) ~[hugegraph-api-0.13.0.jar:0.69.0.0]
	at com.baidu.hugegraph.core.GraphManager.<init>(GraphManager.java:96) ~[hugegraph-api-0.13.0.jar:0.69.0.0]
	at com.baidu.hugegraph.server.ApplicationConfig$GraphManagerFactory$1.onEvent(ApplicationConfig.java:130) ~[hugegraph-api-0.13.0.jar:0.69.0.0]
	at org.glassfish.jersey.server.internal.monitoring.CompositeApplicationEventListener.onEvent(CompositeApplicationEventListener.java:49) ~[jersey-server-3.0.3.jar:?]
	at org.glassfish.jersey.server.internal.monitoring.MonitoringContainerListener.onStartup(MonitoringContainerListener.java:56) ~[jersey-server-3.0.3.jar:?]
	at org.glassfish.jersey.server.ApplicationHandler.onStartup(ApplicationHandler.java:711) ~[jersey-server-3.0.3.jar:?]
	at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.start(GrizzlyHttpContainer.java:330) ~[jersey-container-grizzly2-http-3.0.3.jar:?]
	at org.glassfish.grizzly.http.server.HttpHandlerChain.start(HttpHandlerChain.java:376) ~[grizzly-http-server-3.0.1.jar:3.0.1]
	at org.glassfish.grizzly.http.server.HttpServer.setupHttpHandler(HttpServer.java:268) ~[grizzly-http-server-3.0.1.jar:3.0.1]
	at org.glassfish.grizzly.http.server.HttpServer.start(HttpServer.java:245) ~[grizzly-http-server-3.0.1.jar:3.0.1]
	at com.baidu.hugegraph.server.RestServer.start(RestServer.java:73) ~[hugegraph-api-0.13.0.jar:0.69.0.0]
	at com.baidu.hugegraph.server.RestServer.start(RestServer.java:180) ~[hugegraph-api-0.13.0.jar:0.69.0.0]
	at com.baidu.hugegraph.dist.HugeRestServer.start(HugeRestServer.java:34) ~[hugegraph-dist-0.13.0.jar:?]
	at com.baidu.hugegraph.dist.HugeGraphServer.<init>(HugeGraphServer.java:62) ~[hugegraph-dist-0.13.0.jar:?]
	at com.baidu.hugegraph.dist.HugeGraphServer.main(HugeGraphServer.java:122) ~[hugegraph-dist-0.13.0.jar:?]
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make public static synchronized void jdk.internal.reflect.Reflection.registerFieldsToFilter(java.lang.Class,java.lang.String[]) accessible: module java.base does not "exports jdk.internal.reflect" to unnamed module @49070868
	at java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:340) ~[?:?]
	at java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:280) ~[?:?]
	at java.lang.reflect.Method.checkCanSetAccessible(Method.java:198) ~[?:?]
	at java.lang.reflect.Method.setAccessible(Method.java:192) ~[?:?]
	at com.baidu.hugegraph.util.Reflection.registerFieldsToFilter(Reflection.java:89) ~[hugegraph-core-0.13.0.jar:2.1.2.0]
	at com.baidu.hugegraph.auth.HugeFactoryAuthProxy.registerPrivateActions(HugeFactoryAuthProxy.java:94) ~[hugegraph-api-0.13.0.jar:0.69.0.0]
	at com.baidu.hugegraph.auth.HugeFactoryAuthProxy.<clinit>(HugeFactoryAuthProxy.java:75) ~[hugegraph-api-0.13.0.jar:0.69.0.0]
	... 19 more

@imbajin

it's not easy to handle 1.7.xxx_xxx & 10.xx.xxx or 11.03.233

One way is we truncate the num before the 2nd . & trans it to int number (avoid using float)

  • 1.7.xxx_xxx --> 1.7 --> 7
  • 1.8.xxx_xxx --> 1.8 --> 8
  • 11.1.233 --> 11.1 --> 11

try this command: (check the logic)

java -version 2>&1 | head -1 | cut -d'"' -f2 | sed 's/^1\.//' | cut -d'.' -f1, it replace 1.7.xxx --> 7.xxx so that we could cut the first num to compare directly

@imbajin

@zyxxoo start with java11, the log alert the warning:
image

javeme

zyxxoo

@imbajin