Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.time.* support ? #869

Open
sureshg opened this issue Apr 6, 2023 · 2 comments
Open

java.time.* support ? #869

sureshg opened this issue Apr 6, 2023 · 2 comments
Assignees

Comments

@sureshg
Copy link

sureshg commented Apr 6, 2023

Wasm compilation fails when using LocalDateTime.now()

Env

Java: OpenJDK 20
bytecoder = "2023-04-05"

Error

Caused by: java.lang.IllegalStateException: No such method : Parsing method body of LMain;.main
 Parsing method body of Ljava/time/LocalDateTime;.now
  Parsing method body of Ljava/time/Clock;.systemDefaultZone
   Parsing method body of Ljava/time/ZoneId;.systemDefault
    Parsing method body of Ljava/util/TimeZone;.getDefault
     Parsing method body of Ljava/util/TimeZone;.getDefaultRef
      Parsing method body of Ljava/util/TimeZone;.setDefaultZone
       Parsing method body of Ljdk/internal/util/StaticProperty;.<clinit>
         Visiting #2 INVOKESTATIC Stack size is 0 Source line 63
         Visiting #3 ASTORE Stack size is 1 Source line 63
         Stack 0 of type Ljava/util/Properties;
        ....
         Local 0 of type Ljava/util/Properties;
         Stack 0 of type Ljava/lang/String;
         Stack 1 of type Ljava/nio/charset/Charset;
de.mirkosertic.bytecoder.core.ir.AnalysisException: java.lang.IllegalStateException: No such method : java/nio/charset/Charset.forName(Ljava/lang/String;Ljava/nio/charset/Charset;)Ljava/nio/charset/Charset;
        at de.mirkosertic.bytecoder.core.ir.ResolvedMethod.parseBody(ResolvedMethod.java:50)
        at de.mirkosertic.bytecoder.core.ir.ResolvedClass.resolveMethodInternal(ResolvedClass.java:133)
        at de.mirkosertic.bytecoder.core.ir.ResolvedClass.resolveMethod(ResolvedClass.java:109)
        at de.mirkosertic.bytecoder.core.ir.ResolvedClass.requestInitialization(ResolvedClass.java:97)
        at de.mirkosertic.bytecoder.core.parser.CompileUnit.resolveClass(CompileUnit.java:137)
        at de.mirkosertic.bytecoder.core.parser.GraphParser.parse_INVOKESTATIC(GraphParser.java:828)
        at de.mirkosertic.bytecoder.core.parser.GraphParser.parseMethodInsNode(GraphParser.java:860)
        at de.mirkosertic.bytecoder.core.parser.GraphParser.parse(GraphParser.java:2570)
        at de.mirkosertic.bytecoder.core.parser.GraphParser.parse(GraphParser.java:405)
        at de.mirkosertic.bytecoder.core.parser.GraphParser.<init>(GraphParser.java:150)
        ...
Caused by: java.lang.IllegalStateException: No such method : java/nio/charset/Charset.forName(Ljava/lang/String;Ljava/nio/charset/Charset;)Ljava/nio/charset/Charset;
        at de.mirkosertic.bytecoder.core.ir.ResolvedClass.resolveMethod(ResolvedClass.java:111)
        at de.mirkosertic.bytecoder.core.parser.GraphParser.parse_INVOKESTATIC(GraphParser.java:829)
        at de.mirkosertic.bytecoder.core.parser.GraphParser.parseMethodInsNode(GraphParser.java:860)
        at de.mirkosertic.bytecoder.core.parser.GraphParser.parse(GraphParser.java:2570)
@sdeleuze
Copy link

sdeleuze commented Apr 7, 2023

Regardless of the lack of Charset.forName implementation, I guess this will require platform (JavaScript now, potentially WASI later) integration right? I am wondering if we could take shortcut for such popular use case like directly leveraging Date.now() instead of the regular implementation that requires all the timezone management.

Same should be possible with WASI.

@mirkosertic mirkosertic self-assigned this Apr 9, 2023
@mirkosertic
Copy link
Owner

Thank you for using Bytecoder and submitting a detailed problem description.

Indeed, current Bytecoder version does not support Class.forName() and other Java reflection APIs. They still need to be implemented to a certain point, but were not a top level priority during the latest major refactoring.

However, as @sdeleuze mentioned, Bytecoder does not include Charset or Timezone data. Access to this data must be provided as a JavaScript implementation for both JS and Wasm backends. My initial guess is that this implementation is straight forward, and maybe I'll find time in the next days to do so.,

mirkosertic added a commit that referenced this issue Apr 20, 2023
- Prototypal implementation, not complete yet.
mirkosertic added a commit that referenced this issue Feb 12, 2024
- Prototypal implementation, not complete yet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants