[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String null comparison failure

From: Konstantin L. Metlov
Subject: Re: String null comparison failure
Date: Tue, 04 Jan 2022 19:43:09 +0300
User-agent: Horde Application Framework 5

Happy New Year, Mark !

Thank you for the bug report !

Indeed, JEL used to strictly follow JLS for string comparison, but then for JEL 0.9.8 someone requested a full string comparison support (complete with collation rules). It was indeed a very good idea, but since that version the strings started to be treated differently from other objects. Their comparison was delegated to java.text.Collator, which by default throws an exception on null arguments. It was possible to override this behaviour in collator without modifying JEL, but I agree that not following the JLS for string comparisons by default is a bug.

I've made a pre-release version of JEL 2.1.3, fixing this bug (and adding a few more tests for string comparison) and also committed this fix on Savannah. You can download the pre-release from:

The sha256sum is:

With the best regards,

Quoting Mark Taylor <>:

Dear Konstantin,

happy new year!  And a JEL question.

If I evaluate a string equality test in which one of the operands is null,
a NullPointerException results, e.g.:


provokes a NullPointerException if x has the value null.
Since the equivalent test in Java simply returns false, that's not
what I was expecting.  Is this intended behaviour?

The following program illustrates this:

    import gnu.jel.CompiledExpression;
    import gnu.jel.Evaluator;
    import gnu.jel.Library;

    public class Cmp {
        public static void main(String[] args) throws Throwable {
Library lib = new Library(new Class[] {Cmp.ALib.class}, null, null, null, null);
            compare("textValue", lib);
            compare("nullValue", lib);
private static void compare(String func, Library lib) throws Throwable {
            String txtExpr = func;
            String cmpExpr = func + "==\"abc\"";

            CompiledExpression txtCompex = Evaluator.compile(txtExpr, lib);
            CompiledExpression cmpCompex = Evaluator.compile(cmpExpr, lib);

            report(txtExpr, txtCompex);
            report(cmpExpr, cmpCompex);
private static void report(String expr, CompiledExpression compex) throws Throwable {
            Object result = compex.evaluate(null);
            System.out.println("    -> " + represent(result));
        private static String represent(Object obj) {
            if (obj == null) {
                return "null";
            else if (obj instanceof String) {
                return "\"" + obj + "\"";
            else {
                return obj.toString();
        public static class ALib {
            public static String textValue() {
                return "text";
            public static String nullValue() {
                return null;

which produces the output (JEL 2.1.2):

        -> "text"
        -> false

        -> null
    Exception in thread "main" java.lang.NullPointerException
at at
            at dump.evaluate_boolean(Unknown Source)
at gnu.jel.CompiledExpression.evaluate(
            at Cmp.main(



Mark Taylor  Astronomical Programmer  Physics, Bristol University, UK

reply via email to

[Prev in Thread] Current Thread [Next in Thread]