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

null converts into "null" literal string #23

Open
n3integration opened this issue Nov 14, 2012 · 2 comments
Open

null converts into "null" literal string #23

n3integration opened this issue Nov 14, 2012 · 2 comments

Comments

@n3integration
Copy link

Running the following test against MVEL 2.1.3.Final, a null value is being converted into the string "null", which is not the desired behavior. The expectation is that a null value will remain null rather than be converted to the string literal null.

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import org.mvel2.MVEL;
import org.mvel2.ParserContext;

public class MVELTest {

    public static void main(String[] _args) {
        Map<String, Object> params = new HashMap<String, Object>();
        Map<String, Object> values = new HashMap<String, Object>();

        ParserContext ctx = new ParserContext();
        ctx.addImport("str", MVELTest.class);

        Serializable func = MVEL.compileExpression("def upper(s) { str.toUpper(s); }", ctx);
        MVEL.executeExpression(func, params);

        Serializable defn = MVEL.compileExpression("upper(mapped.value)", ctx);

        params.put("mapped", values);

        runThrough(1, null, defn, values, params);
        runThrough(100, "foo", defn, values, params);
        runThrough(1, null, defn, values, params);
    }

    public static void runThrough(int times, final String val, final Serializable defn, final Map<String, Object> values, final Map<String, Object> params) {
        for(int i = 0; i < times; ++i) {
            values.put("value", val);
            System.err.println(MVEL.executeExpression(defn, params));
        }
    }

    public static String toUpper(String val) {
        if(val == null) {
            return null;
        }
        return val.toUpperCase();
    }
}
@n3integration
Copy link
Author

Cross-posting an issue from another user logged in the codehaus issue tracker.

@Volanx
Copy link

Volanx commented Mar 5, 2018

hello, we still encounter this problem, could you please share some suggestion? I tried to visit the link "http://jira.codehaus.org/browse/MVEL-274" in your comment, however it seems expired.

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