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

NPE & return with Error: incomplete statement: (possible use of reserved keyword as identifier) #320

Open
orzyoung opened this issue Feb 16, 2023 · 2 comments

Comments

@orzyoung
Copy link

orzyoung commented Feb 16, 2023

version: 2.4.4.Final
Not quite sure if the issue already been fixed or not in the later versions, haven't try yet

ERROR
Error: incomplete statement: (possible use of reserved keyword as identifier)

The code that can reproduce the issue

public class Test {
    private static String LEVEL1 = "level1Key";
    private static String LEVEL2 = "level2Key";
    private static String NON_ASCII = "[^\\x00-\\x7F]";

    public static void main(String[] args) {
        String expression = "'value : ' + (level1Key.level2Key)";

        Map<String, Object> context = new HashMap<>();
        Map<String, Object> secondLayerMap = new HashMap<>();
        List<Object> list = new ArrayList<>();

        list.add("content1");
        list.add("content2");

        secondLayerMap.put(LEVEL2, list);
        context.put(LEVEL1, secondLayerMap);

//        I believe there's still some other pre-handling that can be applied
//        but in my project, exclude those non-ASCII is already enough
//        expression = expression.replaceAll(NON_ASCII, " ");
        Object result = null;
        try {
            result = MVEL.eval(expression, context);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(result);
    }
}

When I debug the issue, I found the NBSP charater is the root cause. The ASCII code of NBSP is 160. Within the implementation of MVEL, the NBSP won't be recognized as a whitespace character(so here an alternative way is to enhance the method about determine whether one character is whitespace or not), and lead to the cursor not moved correctly. Further it will lead to the issue. And finally the NPE throw out seems doesn't make sense as well as the error message: possible use of reserved keyword as identifier

Of course, I can use replaceAll to solve this issue, and currently it can fulfill my requirements, but it can be great if we can have a "fix" for this, maybe add some more generic pre-handling to avoid the similar issues. For example, do some replacement for those non-printable Unicode and control charaters....

@huajiaohuixiang
Copy link

i meet this problem too, but i dont know why expression contains "[^\\x00-\\x7F]" ?

@huajiaohuixiang
Copy link

i meet this problem too, but i dont know why expression contains "[^\\x00-\\x7F]" ?

2.4.7.Final 可以正常运行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