Message9124

Author santa4nt
Recipients santa4nt
Date 2014-10-09.18:56:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1412880998.72.0.178567043062.issue2216@psf.upfronthosting.co.za>
In-reply-to
Content
Observe:

Jython 2.7b3+ (default:2c45f75a5406, Oct 7 2014, 17:21:51) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_67
Type "help", "copyright", "credits" or "license" for more information.
>>> from java.math import BigInteger
>>> a = BigInteger('10')
>>> type(a)
<type 'java.math.BigInteger'>
>>> a > 100
True

----------

The errant return value comes from this injected method in PyJavaType.java:

(lines 904-921)

    private static abstract class ComparableMethod extends PyBuiltinMethodNarrow {
        protected ComparableMethod(String name, int numArgs) {
            super(name, numArgs);
        }
        @Override
        public PyObject __call__(PyObject arg) {
            Object asjava = arg.__tojava__(Object.class);
            int compare;
            try {
                compare = ((Comparable<Object>)self.getJavaProxy()).compareTo(asjava);
            } catch(ClassCastException classCast) {
                return Py.NotImplemented;
            }
            return getResult(compare) ? Py.True : Py.False;
        }

        protected abstract boolean getResult(int comparison);
    }

In particular, a ClassCastException was thrown.

Which, when reduced, come to this simplified Java snippet:

import java.math.BigInteger;

public class BigCompare {

    public static void main(String[] args) {
        Object bi = (Object) new BigInteger("10");
        Object i = (Object) new Integer(100);
        System.out.println("" + ((Comparable<Object>)bi).compareTo(i));
    }   
}

$ java BigCompare 
Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigInteger
        at java.math.BigInteger.compareTo(BigInteger.java:99)
        at BigCompare.main(BigCompare.java:8)
History
Date User Action Args
2014-10-09 18:56:38santa4ntsetrecipients: + santa4nt
2014-10-09 18:56:38santa4ntsetmessageid: <1412880998.72.0.178567043062.issue2216@psf.upfronthosting.co.za>
2014-10-09 18:56:38santa4ntlinkissue2216 messages
2014-10-09 18:56:37santa4ntcreate