jarray broken in Jython 2.7.0?

Chris Clark <[email protected]> Sat, 9 Apr 2016 03:24:24 +0000
Newsgroups gmane.comp.lang.jython.user
Message-ID <DM2PR0601MB1294AE4909BFD50AC922EBE09F920@DM2PR0601MB1294.namprd06.prod.outlook.com>
TL;DR I need a way to convert str type into a Java array of bytes type, jarray used to be the way to do this with all previous versions of Jython before 2.7.

I'm seeing a change in behavior in Jython 2.7.0 compared with Jython 2.5.3 related to jarray and bytes.

    Jython 2.5.3 (2.5:c56500f08d34+, Aug 13 2012, 14:48:36)
    [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_67
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import jarray
    >>> sval = 'a string'
    >>> print type(sval)
    <type 'str'>
    >>> x = jarray.array(sval, 'b')
    >>>

Above works fine.

    Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
    [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_67
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import jarray
    >>> sval = 'a string'
    >>> print type(sval)
    <type 'str'>
    >>> x = jarray.array(sval, 'b')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: Type not compatible with array type

Above fails :-(

I can't see anything in the docs about this. There is the new bytearray support in Jython 2.7.0 which appears to work for the above example:

    >>> x = jarray.array(bytearray(sval), 'b')

But this doesn't really work once things get more complicated.

    >>> sval = ''.join([chr(z) for z in range(0xff + 1)])
    >>> x = jarray.array(bytearray(sval), 'b')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OverflowError: value too large for byte

I don't even know what too large might mean, it seems to be a problem with values above 128.

This is preventing blob/binary support from working in jyjdbc (https://bitbucket.org/clach04/jyjdbc/) with Jython 2.7.0, binary works fine in Jython 2.2 and 2.5.3.

Thanks,

Chris


------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial! http://pubads.g.doubleclick.net/
gampad/clk?id=1444514301&iu=/ca-pub-7940484522588532