Our SAST shows possible NullPointerException in https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/runtime/ThreadContext.java#L937
private RubyStackTraceElement[] getPartialTrace(int level, Integer length, Stream<StackWalker.StackFrame> stackStream) {
if (length != null && length == 0) return RubyStackTraceElement.EMPTY_ARRAY;
return TraceType.Gather.CALLER.getBacktraceData(this, stackStream).getPartialBacktrace(runtime, level + length);
}
If length can be null, then it will cause NPE at level + length
Environment Information
We are analyzing versions 9.4.x (8-12), but this problem is still in master
Expected Behavior
- No NPE at all. But it seems nobody catch it through the years, so i don't know if this Integer may hold null at all
Actual Behavior
- have no tests to show this NPE, can't figure out how to make one. This is simply code analysis, that showed possible NPE
Our SAST shows possible NullPointerException in https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/runtime/ThreadContext.java#L937
If
lengthcan be null, then it will cause NPE atlevel + lengthEnvironment Information
We are analyzing versions 9.4.x (8-12), but this problem is still in master
Expected Behavior
Actual Behavior