mirror of
https://github.com/enso-org/enso.git
synced 2024-12-21 11:31:32 +03:00
Improve backend error handling (#11136)
- Fix debug logging for #11088 case--attempt to create an exception that is its own cause fails. - In case the parser is used after closing, throw an `IllegalStateException` instead of UB. (This case is not known to occur and doesn't seem to be behind the #11121, but we should handle it more safely if it does.)
This commit is contained in:
parent
f05997d58c
commit
e587d564f8
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user