Skip to content
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

Calling constructor may break stack map when "assert" option is disabled #119

Closed
HeartSaVioR opened this issue Mar 14, 2020 · 2 comments
Closed

Comments

@HeartSaVioR
Copy link
Contributor

This is another one of test failures I've seen in Spark with Janino 3.1.1.

Please add below tests into ExpressionEvaluatorTest and run to see the failures:

    @Test public void
    testIssue() throws Exception {
        try {
            // This only happens when assert is disabled, so we disable it temporary.
            CodeContext.class.getClassLoader().setClassAssertionStatus(CodeContext.class.getName(), false);

            IScriptEvaluator eval = new ScriptEvaluator();
            eval.setReturnType(Object.class);
            eval.cook(
                ""
                    + "class A {\n"
                    + "    private int val1;\n"
                    + "    private int val2;\n"
                    + "    public A(int v1, int v2) {\n"
                    + "         val1 = v1;\n"
                    + "         val2 = v2;\n"
                    + "    }\n"
                    + "    public int getValue1() {\n"
                    + "        return val1;\n"
                    + "    }\n"
                    + "    public int getValue2() {\n"
                    + "        return val2;\n"
                    + "    }\n"
                    + "}\n"
                    + "Integer a = 1;"
                    + "Object[] b = new Object[]{\n"
                    // Technically stack map will be broken while calling constructor, but to force checking
                    // stack map and make test fail, we leverage ternary operator.
                    + "a == null ? null : new A(3, 4).getValue1()};\n"
                    + "return b;"
            );
            Object[] ret = (Object[]) eval.evaluate(new Object[]{});
            Assert.assertEquals(3, ret[0]);
        } finally {
            CodeContext.class.getClassLoader().setClassAssertionStatus(CodeContext.class.getName(), false);
        }
    }

The culprit looks to be here:

/**
* Asserts that the top operand is an {@code uninitialized_variable_info} and pops it.
*/
public void
popUninitializedVariableOperand() {
assert this.popOperand() instanceof StackMapTableAttribute.UninitializedVariableInfo;
}

Here assertion calls "stateful" method which affects result if assertion is disabled.

@HeartSaVioR HeartSaVioR changed the title Calling constructor breaks stack map when "assert" option is disabled Calling constructor may break stack map when "assert" option is disabled Mar 14, 2020
HeartSaVioR added a commit to HeartSaVioR/janino that referenced this issue Mar 14, 2020
…nitializedVariableOperand() via moving popOperand() out of "assert"
@HeartSaVioR
Copy link
Contributor Author

#120

@aunkrig
Copy link
Member

aunkrig commented Mar 16, 2020

Merged PR #120 which fixes this issue.

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