For general reference I believe NoClassDefFoundError also occurs when the
static initialization block of the required class fails to initialize. In
general, it's best to wrap any static initialization block with a failure
catch that prints/logs the issues before throwing so you aren't struggling
like this. We should open a ticket to make this change if we a place where
that isn't happening. It looks like MemoryUtil's initialization block
doesn't handle this. (It tries to throw.) I believe that in some cases (all
cases?) those throws are swallowed and the NoClassDefFoundError is thrown
instead.

On Mon, Jul 18, 2022 at 1:22 PM David Dali Susanibar Arce <
[email protected]> wrote:

> Hi Olo,
>
> Please if you could try to execute your project by command line (main
> class name example: TestMyFlightConsumer)
>
> $ cd <wks>
> $ export
> JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home
> $ java --version
> openjdk 17.0.3 2022-04-19 LTS
> OpenJDK Runtime Environment Zulu17.34+19-CA (build 17.0.3+7-LTS)
> OpenJDK 64-Bit Server VM Zulu17.34+19-CA (build 17.0.3+7-LTS, mixed mode,
> sharing)
> $ mvn -q dependency:build-classpath -DincludeTypes=jar
> -Dmdep.outputFile=localtest.cp.tmp
> $ javac --add-opens=java.base/java.nio=ALL-UNNAMED
> src/main/java/TestMyFlightConsumer.java --class-path `cat
> localtest.cp.tmp`:target/classes
> $ java --add-opens=java.base/java.nio=ALL-UNNAMED --class-path `cat
> localtest.cp.tmp`:target/classes TestMyFlightConsumer
>
> Please let us know what errors you see now.
>
> David
>
> El lun, 18 jul 2022 a las 12:41, Olo Sawyerr (<[email protected]>)
> escribió:
>
>> Hi,
>>
>> I'm using Java 17. But compiled to target JDK 11 binary.
>>
>> /Users/olo/Library/Java/JavaVirtualMachines/azul-17.0.3/
>>
>> Strange thing is that the *org.apache.arrow.memory.util.MemoryUtil *class
>> appears in the debugger. But when it calls MemoryUtil.directBuffer(address,
>> length) it gives the java.lang.NoClassDefFoundError
>>
>> Yes I'm also passing the flags -
>>
>> --add-opens=java.base/java.nio=ALL-UNNAMED
>>
>> Regards,
>>
>> Olo
>>
>> ------------------------------
>> *From:* David Li <[email protected]>
>> *Sent:* 18 July 2022 18:01
>> *To:* dl <[email protected]>
>> *Subject:* Re: [JAVA] java.lang.NoClassDefFoundError: Could not
>> initialize class org.apache.arrow.memory.util.MemoryUtil
>>
>> Hi,
>>
>> It's specifically "could not initialize class", is there other output?
>>
>> Most likely I'd guess you're on Java 9+, are all the necessary flags
>> passed to java to enable unsafe memory on this version?
>> https://arrow.apache.org/docs/dev/java/install.html#java-compatibility
>> <https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Farrow.apache.org%2Fdocs%2Fdev%2Fjava%2Finstall.html%23java-compatibility&data=05%7C01%7C%7C635738eb6d744d854e6d08da68df27ad%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637937604889560404%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=C%2BwgSBfq0kf%2BXP06shkWtcFgTSIq6%2BWDUCD29idt%2FtQ%3D&reserved=0>
>>
>> -David
>>
>> On Mon, Jul 18, 2022, at 12:56, Olo Sawyerr wrote:
>>
>> Hi,
>>
>> I'm trying to use arrow flight and keep getting this exception below when
>> calling flightClient.getStream() - *java.lang.NoClassDefFoundError:
>> Could not initialize class org.apache.arrow.memory.util.MemoryUtil*
>>
>> It's quite odd because I have *arrow-memory-core* defined in my pom. I'm
>> using v8.0.0. Any ideas what this could be? I'm running this in IntelliJ.
>>
>> *Code:*
>>
>> try (var allocator = new RootAllocator(); var flightClient = 
>> FlightClient.*builder*(allocator, location).build()) {
>>     var flightStream = flightClient.getStream(ticket);
>>     if (flightStream.next()) {
>>         retval = flightStream.getRoot();
>>     }
>> }
>>
>>
>> *StackTrace:*
>>
>> 2022-07-18T17:29:58.075+0100 INFO grpc-default-executor-11 stderr 
>> *java.lang.NoClassDefFoundError:
>> Could not initialize class org.apache.arrow.memory.util.MemoryUtil*
>>
>> 2022-07-18T17:29:58.076+0100 INFO grpc-default-executor-11 stderr at
>> org.apache.arrow.memory.ArrowBuf.getDirectBuffer(ArrowBuf.java:228)
>>
>> 2022-07-18T17:29:58.077+0100 INFO grpc-default-executor-11 stderr at
>> org.apache.arrow.memory.ArrowBuf.nioBuffer(ArrowBuf.java:223)
>>
>> 2022-07-18T17:29:58.077+0100 INFO grpc-default-executor-11 stderr at
>> org.apache.arrow.flight.grpc.GetReadableBuffer.readIntoBuffer(GetReadableBuffer.java:91)
>>
>> 2022-07-18T17:29:58.078+0100 INFO grpc-default-executor-11 stderr at
>> org.apache.arrow.flight.ArrowMessage.frame(ArrowMessage.java:319)
>>
>> 2022-07-18T17:29:58.079+0100 INFO grpc-default-executor-11 stderr at
>> org.apache.arrow.flight.ArrowMessage.access$100(ArrowMessage.java:68)
>>
>> 2022-07-18T17:29:58.079+0100 INFO grpc-default-executor-11 stderr at
>> org.apache.arrow.flight.ArrowMessage$ArrowMessageHolderMarshaller.parse(ArrowMessage.java:551)
>>
>> 2022-07-18T17:29:58.079+0100 INFO grpc-default-executor-11 stderr at
>> org.apache.arrow.flight.ArrowMessage$ArrowMessageHolderMarshaller.parse(ArrowMessage.java:536)
>>
>> 2022-07-18T17:29:58.079+0100 INFO grpc-default-executor-11 stderr at
>> io.grpc.MethodDescriptor.parseResponse(MethodDescriptor.java:284)
>>
>> 2022-07-18T17:29:58.080+0100 INFO grpc-default-executor-11 stderr at
>> io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInternal(ClientCallImpl.java:661)
>>
>> 2022-07-18T17:29:58.080+0100 INFO grpc-default-executor-11 stderr at
>> io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInContext(ClientCallImpl.java:646)
>>
>> 2022-07-18T17:29:58.080+0100 INFO grpc-default-executor-11 stderr at
>> io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
>>
>> 2022-07-18T17:29:58.081+0100 INFO grpc-default-executor-11 stderr at
>> io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133)
>>
>> 2022-07-18T17:29:58.081+0100 INFO grpc-default-executor-11 stderr at
>> java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
>>
>> 2022-07-18T17:29:58.081+0100 INFO grpc-default-executor-11 stderr at
>> java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
>>
>>
>>

Reply via email to