Description
When ActiveMQ running ActiveMQ on Java 17 or later JRE, it encounters following exception:
ERROR | Could not set property soTimeout on ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=xxxxx] | org.apache.activemq.util.IntrospectionSupport | main java.lang.reflect.InaccessibleObjectException: Unable to make public void sun.nio.ch.ServerSocketAdaptor.setSoTimeout(int) throws java.net.SocketException accessible: module java.base does not "opens sun.nio.ch" to unnamed module @4739cd70 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199) at java.base/java.lang.reflect.Method.setAccessible(Method.java:193) at org.apache.activemq.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:179) at org.apache.activemq.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:155) at org.apache.activemq.transport.tcp.TcpTransportServer.configureServerSocket(TcpTransportServer.java:202) at org.apache.activemq.transport.tcp.TcpTransportServer.bind(TcpTransportServer.java:144) at org.apache.activemq.transport.auto.nio.AutoNioSslTransportFactory.doBind(AutoNioSslTransportFactory.java:122) at org.apache.activemq.transport.TransportFactorySupport.bind(TransportFactorySupport.java:40) at org.apache.activemq.broker.TransportConnector.createTransportServer(TransportConnector.java:340) at org.apache.activemq.broker.TransportConnector.getServer(TransportConnector.java:148) at org.apache.activemq.broker.TransportConnector.asManagedConnector(TransportConnector.java:113) at org.apache.activemq.broker.BrokerService.registerConnectorMBean(BrokerService.java:2241) at org.apache.activemq.broker.BrokerService.startTransportConnector(BrokerService.java:2728) at org.apache.activemq.broker.BrokerService.startAllConnectors(BrokerService.java:2624) at org.apache.activemq.broker.BrokerService.doStartBroker(BrokerService.java:762) at org.apache.activemq.broker.BrokerService.startBroker(BrokerService.java:724) at org.apache.activemq.broker.BrokerService.start(BrokerService.java:622)
According to Oracle, with JEP 403 (link1) and JEP 403 (link2) which has been decided to be delivered from JDK 17 and onwards , the setAccessible approach which was introduced as part of https://issues.apache.org/jira/browse/AMQ-7121 wont work.
Fix: Adding the following in activemq file should do the job:
--add-opens java.base/sun.nio.ch=ALL-UNNAMED