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

Possible NPE in BasicCompilerPassListener:endExecute() found by SAST #8811

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 · 1 comment
Open

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/passes/BasicCompilerPassListener.java#L45

    public void endExecute(CompilerPass pass, FullInterpreterContext fic, Object data, boolean childScope) {
        Long startTime = times.get(pass);
        long timeTaken = startTime != null ? System.currentTimeMillis() - startTime.longValue() : -1;

...

        if (startTime > 0) {
            LOG.info("Finished " + pass.getLabel() + " on scope in " + timeTaken + "ms.");
        } else { // Not really sure we should allow same pass to be run twice in same pass order run...too defensive?
            LOG.info("Finished " + pass.getLabel() + " on scope " + fic.getScope());
        }
    }

If startTime may be null, then it will cause NPE at startTime > 0.

Maybe it is mistype and conditional should be timeTaken > 0?

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 Long 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
@headius
Copy link
Member
headius commented Apr 30, 2025

This is another case where it may never actually be null. The times map gets populated when the compiler pass starts, so there should always be an entry for the pass there. I'm not sure the best way to deal with this since we don't have a Map type for Object to int. 🤔

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

No branches or pull requests

2 participants
0