incubator-jena-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simon Helsen (JIRA)" <>
Subject [jira] [Commented] (JENA-91) byte area for lengths is read in platform endian, but expects big endian
Date Mon, 08 Aug 2011 22:16:27 GMT


Simon Helsen commented on JENA-91:

I obviously misunderstood the code. The lengthBuffer.get reads the 4 bytes as the value, so
the endian-ness is not the problem. The problem is the large value :-). I'll update the title/description

> byte area for lengths is read in platform endian, but expects big endian
> ------------------------------------------------------------------------
>                 Key: JENA-91
>                 URL:
>             Project: Jena
>          Issue Type: Bug
>          Components: TDB
>         Environment: Windows (and I presume any little endian system)
>            Reporter: Simon Helsen
>            Priority: Critical
> I tried to debug the OME and check why a bytebuffer is causing my native memory to explode
in almost no time. It all seems to happen in this bit of code in com.hp.hpl.jena.tdb.base.objectfile.ObjectFileStorage
(lines 243 onwards)
>   // No - it's in the underlying file storage.
>         lengthBuffer.clear() ;
>         int x =, loc) ;
>         if ( x != 4 )
>             throw new FileException(""+loc+")["+filesize+"]["+file.size()+"]:
Failed to read the length : got "+x+" bytes") ;
>         int len = lengthBuffer.getInt(0) ;
>         ByteBuffer bb = ByteBuffer.allocate(len) ;
> My debugger shows that x==4. It also shows the lengthBuffer has the following content:
[111, 110, 61, 95], however the value of len=1869495647, which is rather a lot :-) Obviously,
the next statement (ByteBuffer.allocate) causes the OME
> So, looking into it, lengthBuffer.getInt(0)==1869495647, but lenghtBuffer.get(0)==111,
which seems more correct. Then I noticed that the bytebuffer also says bigEndian==true. I
am running all of this on Windows 7. which is to the best of my knowledge little endian
> I think this can only work correctly if the byteBuffer for lengths (at least) have their
order explicitly set to that of the platform. So, somewhere in the code, you'd need to make
sure to set
> lengthBuffer.order(ByteOrder.nativeOrder())
> I think this only affects this particular one because it manages lengths, but I don't
know the code well enough to know if there are other places that may be affected

This message is automatically generated by JIRA.
For more information on JIRA, see:


View raw message