diff --git a/lib/rust/parser/generate-java/java/org/enso/syntax2/Parser.java b/lib/rust/parser/generate-java/java/org/enso/syntax2/Parser.java index 2c375ee8408..91731cdde52 100644 --- a/lib/rust/parser/generate-java/java/org/enso/syntax2/Parser.java +++ b/lib/rust/parser/generate-java/java/org/enso/syntax2/Parser.java @@ -75,10 +75,10 @@ public final class Parser implements AutoCloseable { return false; } - private long state; + private long stateUnlessClosed; private Parser(long stateIn) { - state = stateIn; + stateUnlessClosed = stateIn; } private static native long allocState(); @@ -115,7 +115,16 @@ public final class Parser implements AutoCloseable { return isIdentOrOperator(inputBuf); } + private long getState() { + if (stateUnlessClosed != 0) { + return stateUnlessClosed; + } else { + throw new IllegalStateException("Parser used after close()"); + } + } + public ByteBuffer parseInputLazy(CharSequence input) { + var state = getState(); byte[] inputBytes = input.toString().getBytes(StandardCharsets.UTF_8); ByteBuffer inputBuf = ByteBuffer.allocateDirect(inputBytes.length); inputBuf.put(inputBytes); @@ -123,6 +132,7 @@ public final class Parser implements AutoCloseable { } public Tree parse(CharSequence input) { + var state = getState(); byte[] inputBytes = input.toString().getBytes(StandardCharsets.UTF_8); ByteBuffer inputBuf = ByteBuffer.allocateDirect(inputBytes.length); inputBuf.put(inputBytes); @@ -140,7 +150,7 @@ public final class Parser implements AutoCloseable { @Override public void close() { - freeState(state); - state = 0; + freeState(stateUnlessClosed); + stateUnlessClosed = 0; } } diff --git a/std-bits/base/src/main/java/org/enso/base/polyglot/EnsoMeta.java b/std-bits/base/src/main/java/org/enso/base/polyglot/EnsoMeta.java index d3763348173..6749092ae63 100644 --- a/std-bits/base/src/main/java/org/enso/base/polyglot/EnsoMeta.java +++ b/std-bits/base/src/main/java/org/enso/base/polyglot/EnsoMeta.java @@ -18,7 +18,7 @@ public final class EnsoMeta { var ex = new NullPointerException( "Cannot get type for " + moduleName + " type: " + typeName + " at " + module); - ex.initCause(ex); + ex.initCause(e); throw ex; } }