8000 Possible NPE in StartupInterpreterEngine:InterpreterEngine() found by SAST · Issue #8815 · jruby/jruby · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Possible NPE in StartupInterpreterEngine:InterpreterEngine() found by SAST #8815
Closed as not planned
@ngr-ilmarh

Description

@ngr-ilmarh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0