ClassAliasPool.forName0: "java.lang.ClassNotFoundException: byte[" error when using custom ClassLoader
See original GitHub issueTo reproduce the problem, put all necessary JARs to a temporary directory, like d:/temp/jars:
chronicle-algorithms-1.1.8.jar chronicle-bytes-1.7.34.jar chronicle-core-1.7.15.jar chronicle-map-3.13.0.jar chronicle-threads-1.7.7.jar chronicle-values-1.5.5.jar chronicle-wire-1.7.30.jar javapoet-1.5.1.jar slf4j-api.jar slf4j-nop.jar
Then have following “application” main class:
public class ApplicationMain {
public static void main(String[] args) throws IOException {
System.out.println("Opening and closing");
ChronicleMapBuilder<byte[], byte[]> byteToByte =
ChronicleMapBuilder.of(byte[].class, byte[].class)
.name("sha-to-node")
.entries(1).
averageKeySize(20).
averageValueSize(30);
final File file = new File(args[0]);
ChronicleMap<byte[], byte[]> map = byteToByte.createPersistedTo(file);
map.close();
map = byteToByte.createPersistedTo(file);
map.close();
}
}
and following “bootloader” main class:
public class BootLoaderMain {
public static void main(String[] args) throws Exception {
final List<URL> urls = new ArrayList<>();
final File root = new File("d:/temp/jars");
for (File file : root.listFiles()) {
urls.add(file.toURL());
}
urls.add(BootLoaderMain.class.getResource("."));
final ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), null);
final Class<?> mainClass = classLoader.loadClass("ApplicationMain");
final Method mainMethod = mainClass.getDeclaredMethod("main", String[].class);
mainMethod.invoke(null, new Object[] {new String[] {"d:/temp/chronicle"}});
}
}
Running BootLoaderMain will result in following Exception:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at BootLoaderMain.main(BootLoaderMain.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: net.openhft.chronicle.core.io.IORuntimeException: java.lang.ClassNotFoundException: byte[
at net.openhft.chronicle.wire.Wires$SerializeJavaLang.lambda$apply$3(Wires.java:390)
at net.openhft.chronicle.wire.ScalarStrategy.readUsing(ScalarStrategy.java:74)
at net.openhft.chronicle.wire.ValueIn.object(ValueIn.java:494)
at net.openhft.chronicle.wire.TextWire$TextValueIn.objectWithInferredType0(TextWire.java:2909)
at net.openhft.chronicle.wire.TextWire$TextValueIn.objectWithInferredType(TextWire.java:2882)
at net.openhft.chronicle.wire.ValueIn.object(ValueIn.java:435)
at net.openhft.chronicle.wire.SerializationStrategies$9.readUsing(SerializationStrategies.java:201)
at net.openhft.chronicle.wire.TextWire$TextValueIn.marshallable(TextWire.java:2633)
at net.openhft.chronicle.wire.ValueIn.object(ValueIn.java:482)
at net.openhft.chronicle.wire.TextWire$TextValueIn.objectWithInferredType0(TextWire.java:2909)
at net.openhft.chronicle.wire.TextWire$TextValueIn.objectWithInferredType(TextWire.java:2882)
at net.openhft.chronicle.wire.TextWire$TextValueIn.typedMarshallable(TextWire.java:2694)
at net.openhft.chronicle.map.ChronicleMapBuilder.openWithExistingFile(ChronicleMapBuilder.java:1756)
at net.openhft.chronicle.map.ChronicleMapBuilder.createWithFile(ChronicleMapBuilder.java:1555)
at net.openhft.chronicle.map.ChronicleMapBuilder.createPersistedTo(ChronicleMapBuilder.java:1484)
at ApplicationMain.main(ApplicationMain.java:17)
... 10 more
Caused by: java.lang.ClassNotFoundException: byte[
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at net.openhft.chronicle.core.pool.ClassAliasPool.forName0(ClassAliasPool.java:118)
at net.openhft.chronicle.core.pool.ClassAliasPool.forName(ClassAliasPool.java:107)
at net.openhft.chronicle.wire.Wires$SerializeJavaLang.lambda$apply$3(Wires.java:388)
... 25 more
However, when changing following line:
final ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), null);
to:
final ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]));
it will work as expected. AFAIU, there will be two different Class<byte[]>es and only the boot loader Class<byte[]> is handled correctly.
Motivation:
We are using a small “boot” ClassLoader to bootstrap our application once deployed (but not when developing and starting from the IDE). Now I have source code using Chronicle-Map which is working fine when started from the IDE: it’s using a ChronicleMap<byte[], byte[]> and has no problems accessing a test database file. However, when starting our deployed application, I’m getting above Exception.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)

Top Related StackOverflow Question
I’m facing a similar problem. When the file doesn’t exists there is no exception and the data is stored to file.
This is the interface
This is how I create the map:
And after put all data in map the close() method is invoked. Every time that I try through createPersistedTo() method is throwing the exception below.
Caused by: net.openhft.chronicle.core.io.IORuntimeException: java.lang.ClassNotFoundException: EnderecoServicoInterfaceAny tips?
I am closing this issue as it appears to be solved using the PR merged in Core. @rogeriovalente please raise a separate issue if you still have problems with your map.