Our SAST shows possible NullPointerException
|
Interpreter.LOG.info("I: " + ipc + ", R: " + rescuePCs[ipc] + " - " + instr + ">"); |
or redundant null check in
|
ipc = rescuePCs == null ? -1 : rescuePCs[ipc]; |
public class StartupInterpreterEngine extends InterpreterEngine {
public IRubyObject interpret(ThreadContext context, Block block, IRubyObject self,
InterpreterContext interpreterContext, RubyModule implClass,
String name, IRubyObject[] args, Block blockArg) {
...
int[] rescuePCs = interpreterContext.getRescueIPCs();
...
while (ipc < n) {
Instr instr = instrs[ipc];
Operation operation = instr.getOperation();
if (debug) {
Interpreter.LOG.info("I: " + ipc + ", R: " + rescuePCs[ipc] + " - " + instr + ">");
Interpreter.interpInstrsCount++;
} else if (profile) {
Profiler.instrTick(operation);
Interpreter.interpInstrsCount++;
}
try {
...
} catch (Throwable t) {
if (debug) extractToMethodToAvoidC2Crash(instr, t);
ipc = rescuePCs == null ? -1 : rescuePCs[ipc];
if (debug) {
Interpreter.LOG.info("in : " + interpreterContext.getScope() + ", caught Java throwable: " + t + "; excepting instr: " + instr);
Interpreter.LOG.info("ipc for rescuer: " + ipc);
}
if (ipc == -1) {
Helpers.throwException(t);
} else {
exception = t;
}
}
}
...
If rescuePCs can be null, then NPE will be thrown, if rescuePCs can't be null, then null comparison is redundant.
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 rescuePCs can be 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
jruby/core/src/main/java/org/jruby/ir/interpreter/StartupInterpreterEngine.java
Line 51 in 0e43a52
jruby/core/src/main/java/org/jruby/ir/interpreter/StartupInterpreterEngine.java
Line 106 in 0e43a52
If rescuePCs can be null, then NPE will be thrown, if rescuePCs can't be null, then null comparison is redundant.
Environment Information
We are analyzing versions 9.4.x (8-12), but this problem is still in master
Expected Behavior
Actual Behavior