Whiley / WhileyCompiler

The Whiley Compiler (WyC)
http://whiley.org
Apache License 2.0
217 stars 36 forks source link

java.lang.NullPointerException with latest release #1160

Closed k4rtik closed 2 years ago

k4rtik commented 2 years ago

Hi @DavePearce

The current release doesn't seem to compile even a trivial program anymore.

❯ mkdir hello
❯ cd hello
❯ wy init
❯ wy build
wyc: Exception in thread "main" java.lang.NullPointerException: Cannot invoke "wycc.lang.Syntactic$Item$Descriptor.getOperandLayout()" because the return value of "wycc.lang.Syntactic$Schema.getDescriptor(int)" is null
    at wycc.io.HeapReader.readOperands(HeapReader.java:95)
    at wycc.io.HeapReader.readItem(HeapReader.java:84)
    at wycc.io.HeapReader.readItems(HeapReader.java:65)
    at wyil.io.WyilFileReader.read(WyilFileReader.java:44)
    at wyc.Compiler.extractFromZip(Compiler.java:212)
    at wyc.Compiler.extractDependencies(Compiler.java:191)
    at wyc.Compiler.run(Compiler.java:133)
    at wyc.Compiler.main(Compiler.java:181)
❯ java --version
openjdk 18.0.2 2022-07-19
OpenJDK Runtime Environment Homebrew (build 18.0.2+0)
OpenJDK 64-Bit Server VM Homebrew (build 18.0.2+0, mixed mode, sharing)
k4rtik commented 2 years ago

Just checked that downgrading to v0.6.1 works:

❯ cargo install whiley@0.6.1
[...]
   Compiling whiley v0.6.1
    Finished release [optimized] target(s) in 23.86s
   Replacing /Users/kartik/.cargo/bin/wy
    Replaced package `whiley v0.6.3` with `whiley v0.6.1` (executable `wy`)
❯ wy --version
wy 0.6.0

Oddly version shows up wrong though.

DavePearce commented 2 years ago

Hey @k4rtik ,

Thanks for the reporting this. Looking at, I think there is only one explanation which makes sense. My assumption is that, prior to running v0.6.3 above you had previously compiled Whiley code using an earlier release (e.g. v0.6.1). If that is the case, then I think its a quick fix on your end:

> rm ~/.whiley/repository/*.zip

(if you're not comfortable with the command-line you could do this from file explorer or similar. Just delete the whole .whiley directory)

The short explanation is that of binary compatibility. Moving from v0.6.3 has changed the internal format for the intermediate language stored in the packages. Since you had downloaded them already in a previous compilation, yours were out-of-date and need to be updated.

I suppose the longer issue is that I need to start an upgrade process for packages which is more robust. Thus far, mostly, I've been able to make changes without too much trouble because not may people are actively using the tool.

Anyway, keep me posted if that works!

k4rtik commented 2 years ago

The quick fix is working!

Thanks for a quick turn around on this issue.

DavePearce commented 2 years ago

No worries :)