huangqingwei opened SPR-15970 and commented

Step1. I create a String and Integer Comparator as Follows:

public class StringAndIntegerComparator extends StandardTypeComparator {
    @Override
    public boolean canCompare(Object o, Object o1) {
        if ((o instanceof String && o1 instanceof Integer) || (o1 instanceof String && o instanceof Integer)) {
            return true;
        } else {
            return super.canCompare(o, o1);
        }
    }

    @Override
    public int compare(Object o, Object o1) throws EvaluationException {
        if ((o instanceof String && o1 instanceof Integer) || (o1 instanceof String && o instanceof Integer)) {
            return stringAndIntegercompare(o, o1);
        } else {
            return super.compare(o, o1);
        }
    }

    private int stringAndIntegercompare(Object o, Object o1) {
        Integer oi;
        if (o instanceof String) {
            oi = Integer.parseInt((String) o);
        } else {
            oi = (Integer) o;
        }

        Integer oi1;
        if (o1 instanceof String) {
            oi1 = Integer.parseInt((String) o1);
        } else {
            oi1 = (Integer) o1;
        }
        if (oi > oi1) {
            return 1;
        }
        else if (oi < oi1) {
            return -1;
        }
        else {
            return 0;
        }
    }
}

Step 2. I write a TestComparator using the upper Comparator:

public void testComparator() {
        ExpressionParser parser = new SpelExpressionParser();
        StandardEvaluationContext context = new StandardEvaluationContext();
        context.setTypeComparator(new StringAndIntegerComparator());

        Expression expression = parser.parseExpression("'123' >= 123");
        Assert.assertTrue(expression.getValue(context, Boolean.class)); // true

        expression = parser.parseExpression("'123' == 123");
        Assert.assertTrue(expression.getValue(context, Boolean.class)); // false
    }

So, what I expect is a true of "'123' == 123", but I get false. Thanks.


Affects: 4.3.9

Comment From: spring-projects-issues

huangqingwei commented

Excuse me,can this issue be supported?

Comment From: snicoll

Sorry that this issue got overlooked and thank you for the sample. I've moved it to a small project that builds against a supported version of the framework and both those assertions return true.