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 2c375ee84082..91731cdde522 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 @@ private static boolean searchFromDirToTop(Throwable chain, File root, String... 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 long isIdentOrOperator(CharSequence input) { 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 ByteBuffer parseInputLazy(CharSequence input) { } 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 static String getWarningMessage(Warning warning) { @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 d37633481736..6749092ae631 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 static Value getType(String moduleName, String typeName) { var ex = new NullPointerException( "Cannot get type for " + moduleName + " type: " + typeName + " at " + module); - ex.initCause(ex); + ex.initCause(e); throw ex; } }