[External] : Re: ClassCastException in jextract

Sundararajan Athijegannathan sundararajan.athijegannathan at oracle.com
Tue May 4 14:53:17 UTC 2021


Btw are you trying to extract Objective C header? jextract as of now supports only C declarations. C++, Objective C declarations are not handled. That -C flag exists to pass other arguments/options to clang directly (say preprocessor defines).

Thanks,
-Sundar
________________________________
From: Sebastian Stenzel <sebastianstenzel at gmail.com> on behalf of Sebastian Stenzel <sebastian.stenzel at gmail.com>
Sent: 04 May 2021 20:20
To: Sundararajan Athijegannathan <sundararajan.athijegannathan at oracle.com>
Cc: panama-dev at openjdk.java.net <panama-dev at openjdk.java.net>
Subject: Re: [External] : Re: ClassCastException in jextract

Sorry, this is the correct one:

class jdk.internal.jextract.impl.TypeImpl$1 cannot be cast to class jdk.incubator.jextract.Type$Delegated (jdk.internal.jextract.impl.TypeImpl$1 and jdk.incubator.jextract.Type$Delegated are in module jdk.incubator.jextract of loader 'app')
java.lang.ClassCastException: class jdk.internal.jextract.impl.TypeImpl$1 cannot be cast to class jdk.incubator.jextract.Type$Delegated (jdk.internal.jextract.impl.TypeImpl$1 and jdk.incubator.jextract.Type$Delegated are in module jdk.incubator.jextract of loader 'app')
at jdk.incubator.jextract/jdk.internal.jextract.impl.TreeMaker.createTypedef(TreeMaker.java:245)
at jdk.incubator.jextract/jdk.internal.jextract.impl.TreeMaker.createTreeInternal(TreeMaker.java:102)
at jdk.incubator.jextract/jdk.internal.jextract.impl.TreeMaker.createTree(TreeMaker.java:80)
at jdk.incubator.jextract/jdk.internal.jextract.impl.Parser.lambda$parse$2(Parser.java:86)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
at jdk.incubator.jextract/jdk.internal.jextract.impl.Parser.parse(Parser.java:67)
at jdk.incubator.jextract/jdk.incubator.jextract.JextractTool.parse(JextractTool.java:111)
at jdk.incubator.jextract/jdk.incubator.jextract.JextractTool.run(JextractTool.java:274)
at jdk.incubator.jextract/jdk.incubator.jextract.JextractTool.main(JextractTool.java:170)

On 4. May 2021, at 16:20, Sundararajan Athijegannathan <sundararajan.athijegannathan at oracle.com<mailto:sundararajan.athijegannathan at oracle.com>> wrote:

Thanks.

I just checked line 246 of TreeMaker.java

line 246 now has

  if (canonicalType instanceof Type.Declared) {


which cannot throw ClassCastException. Most likely you've some dated version. Will you please try the latest code?

Thanks,
-Sundar

________________________________
From: Sebastian Stenzel <sebastianstenzel at gmail.com<mailto:sebastianstenzel at gmail.com>> on behalf of Sebastian Stenzel <sebastian.stenzel at gmail.com<mailto:sebastian.stenzel at gmail.com>>
Sent: 04 May 2021 16:26
To: Sundararajan Athijegannathan <sundararajan.athijegannathan at oracle.com<mailto:sundararajan.athijegannathan at oracle.com>>
Cc: panama-dev at openjdk.java.net<mailto:panama-dev at openjdk.java.net> <panama-dev at openjdk.java.net<mailto:panama-dev at openjdk.java.net>>
Subject: [External] : Re: ClassCastException in jextract

Hi,

I need to correct my previous theory. TypeImpl$1 is obviously an anonymous class, most likely TypeImpl.ERROR. Here is the full stack trace:

class jdk.internal.jextract.impl.TypeImpl$1 cannot be cast to class jdk.incubator.jextract.Type$Delegated (jdk.internal.jextract.impl.TypeImpl$1 and jdk.incubator.jextract.Type$Delegated are in module jdk.incubator.jextract of loader 'app')
java.lang.ClassCastException: class jdk.internal.jextract.impl.TypeImpl$1 cannot be cast to class jdk.incubator.jextract.Type$Delegated (jdk.internal.jextract.impl.TypeImpl$1 and jdk.incubator.jextract.Type$Delegated are in module jdk.incubator.jextract of loader 'app')
at jdk.incubator.jextract/jdk.internal.jextract.impl.TreeMaker.createTypedef(TreeMaker.java:246)
at jdk.incubator.jextract/jdk.internal.jextract.impl.TreeMaker.createTreeInternal(TreeMaker.java:103)
at jdk.incubator.jextract/jdk.internal.jextract.impl.TreeMaker.createTree(TreeMaker.java:81)
at jdk.incubator.jextract/jdk.internal.jextract.impl.Parser.lambda$parse$2(Parser.java:86)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
at jdk.incubator.jextract/jdk.internal.jextract.impl.Parser.parse(Parser.java:67)
at jdk.incubator.jextract/jdk.incubator.jextract.JextractTool.parse(JextractTool.java:112)
at jdk.incubator.jextract/jdk.incubator.jextract.JextractTool.run(JextractTool.java:245)
at jdk.incubator.jextract/jdk.incubator.jextract.JextractTool.main(JextractTool.java:157)

I attempted to jextract a macOS lib using the following command:

jextract --source \
    -d /Users/sebastian/Desktop/SRC \
    -lFileProvider \
    -t org.cryptomator.fileprovider \
    -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/ \
    -C"-F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks" \
    -C"-ObjC" \
    -C"-v" \
    -J-Djextract.debug=true \
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/FileProvider.framework/Versions/A/Headers/FileProvider.h

Just out of curiosity I attempted the same for different ObjC libs (such as Foundation.h), the stack trace is always the same. Maybe it is some ObjC language feature that results in an AST that isn't yet supported by jextract?

My setup:
- on macOS 11.3
- Xcode 12.5
- clang version 9.0.0 installed via homebrew

I built the JDK (commit 204518d) using these flags:

--with-boot-jdk=/Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home/
--with-native-debug-symbols=none
--with-debug-level=release
--with-libclang=/usr/local/opt/llvm at 9

Thank you!


On 4. May 2021, at 12:35, Sundararajan Athijegannathan <sundararajan.athijegannathan at oracle.com<mailto:sundararajan.athijegannathan at oracle.com>> wrote:

Hi,

Will you please run jextract with -J-Djextract.debug=true? This should print stack trace on crash. Also, if possible please post header (assuming open source project) or code snippet from there that cases the mentioned failure.

Thanks
-Sundar
________________________________
From: panama-dev <panama-dev-retn at openjdk.java.net<mailto:panama-dev-retn at openjdk.java.net>> on behalf of Sebastian Stenzel <sebastian.stenzel at gmail.com<mailto:sebastian.stenzel at gmail.com>>
Sent: 03 May 2021 11:05
To: panama-dev at openjdk.java.net<mailto:panama-dev at openjdk.java.net> <panama-dev at openjdk.java.net<mailto:panama-dev at openjdk.java.net>>
Subject: ClassCastException in jextract

Hi,

I'm currently attempting to jextract a library on macOS Big Sur but I run into exceptions, both with the latest EA build as well as a locally built snapshot (commit 204518d):

class jdk.internal.jextract.impl.TypeImpl$1 cannot be cast to class jdk.incubator.jextract.Type$Delegated (jdk.internal.jextract.impl.TypeImpl$1 and jdk.incubator.jextract.Type$Delegated are in module jdk.incubator.jextract of loader 'app')

I guess that `TypeImpl$1` refers to `TypeImpl.DelegatedBase`, so the cast should be allowed.

Is there anything I can do to get a more detailed output logged by jextract?

Cheers!
Sebastian



More information about the panama-dev mailing list