Martin Vysny created LUCENE-5855:
------------------------------------

             Summary: BinaryDictionary may fail reading a file
                 Key: LUCENE-5855
                 URL: https://issues.apache.org/jira/browse/LUCENE-5855
             Project: Lucene - Core
          Issue Type: Bug
          Components: modules/analysis
    Affects Versions: 4.9
            Reporter: Martin Vysny


The following code may fail on other JVMs, e.g. on Android:

      final ByteBuffer tmpBuffer = ByteBuffer.allocateDirect(size);
      final ReadableByteChannel channel = Channels.newChannel(dictIS);
      final int read = channel.read(tmpBuffer);
      if (read != size) {
        throw new EOFException("Cannot read whole dictionary");
      }

The code expects that channel.read() will fill entire buffer contents, which is 
however not the case: ReadableByteChannel.read() may even decide to read 0 
bytes and this mimicks InputStream.read() behavior. The current Lucene code 
accidentally works on Oracle Java because Oracle Java channel.read() fills the 
buffer fully (just check the Channels.newChannel() implementation).



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to