8000 Possible NPE in UnboxableOpsAnalysisNode:getUnboxedVar() found by SAST · Issue #8812 · jruby/jruby · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Possible NPE in UnboxableOpsAnalysisNode:getUnboxedVar() found by SAST #8812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ngr-ilmarh opened this issue Apr 29, 2025 · 2 comments · May be fixed by #8813
Open

Possible NPE in UnboxableOpsAnalysisNode:getUnboxedVar() found by SAST #8812

ngr-ilmarh opened this issue Apr 29, 2025 · 2 comments · May be fixed by #8813

Comments

@ngr-ilmarh
Copy link

Our SAST shows possible NullPointerException in https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/ir/dataflow/analyses/UnboxableOpsAnalysisNode.java#L362

    private TemporaryLocalVariable getUnboxedVar(Class reqdType, Map<Variable, TemporaryLocalVariable> unboxMap, Variable v, boolean createNew) {
        TemporaryLocalVariable unboxedVar = unboxMap.get(v);
        // FIXME: This is a bit broken -- SSA will eliminate this need for type verification
        if ((unboxedVar == null && createNew) || !matchingTypes(reqdType, unboxedVar.getType())) {
            unboxedVar = problem.getFIC().getNewUnboxedVariable(reqdType);
            unboxMap.put(v, unboxedVar);
        } else if (unboxedVar == null) {
            // FIXME: throw an exception here
            System.out.println("ERROR: No unboxed var for : " + v);
        }
        return unboxedVar;
    }

If unboxedVar is null and createNew is false, then unboxedVar.getType() will cause NPE. And null unboxedVar is expectable condition, but appears to be unreachable.

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 condition exists 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
@ngr-ilmarh
Copy link
Author

Quick fix in PR

@ngr-ilmarh ngr-ilmarh changed the title Possible NPE in UnboxableOpsAnalysisNode:getUnboxedVar() Possible NPE in UnboxableOpsAnalysisNode:getUnboxedVar() found by SAST Apr 30, 2025
@headius
Copy link
Member
headius commented Apr 30, 2025

Probably the case that we never have a null unboxedVar and also do not want to createNew.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0