You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by "Alejandro Abdelnur (JIRA)" <ji...@apache.org> on 2014/06/04 17:35:02 UTC

[jira] [Comment Edited] (HADOOP-10662) NullPointerException in CryptoInputStream while wrapped stream is not ByteBufferReadable. Add tests using normal stream.

    [ https://issues.apache.org/jira/browse/HADOOP-10662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14017773#comment-14017773 ] 

Alejandro Abdelnur edited comment on HADOOP-10662 at 6/4/14 3:33 PM:
---------------------------------------------------------------------

Yi, the current logic, while correct seems a bit too complex. Under what circumstances you would have an {{InputStream}} that implements {{ByteBufferReadable}} but does not support the {{read(ByteBuffer)}} operation? It seems to me that would be an incorrect implementation of such interface, no?

{code}
      if (usingByteBufferRead == null) {
        if (in instanceof ByteBufferReadable) {
          try {
            n = ((ByteBufferReadable) in).read(inBuffer);
            usingByteBufferRead = Boolean.TRUE;
          } catch (UnsupportedOperationException e) {
            usingByteBufferRead = Boolean.FALSE;
          }
        } else {
          usingByteBufferRead = Boolean.FALSE;
        }
        if (!usingByteBufferRead) {
          n = readFromUnderlyingStream(inBuffer);
        }
      } else {
        if (usingByteBufferRead) {
          n = ((ByteBufferReadable) in).read(inBuffer);
        } else {
          n = readFromUnderlyingStream(inBuffer);
        }
      }
{code}

If we assume that any {{InputStream}} implementing {{ByteBufferReadable}} supports the {{read(ByteBuffer)}} then the above code could be simplified to:

{code}
      if (usingByteBufferRead == null) {
        usingByteBufferRead = (in instanceof ByteBufferReadable);
      }
      if (usingByteBufferRead) {
        n = ((ByteBufferReadable) in).read(inBuffer);
      } else {
        n = readFromUnderlyingStream(inBuffer);
      }
{code}

Or am I missing something obvious?





was (Author: tucu00):
Yi, the current logic, while correct seems a bit too complex. Under what circumstances you would have an {{InputStream}} that implements {{ByteBufferReadable}} but does not support the {{read(ByteBuffer)}} operation? It seems to me that would be an incorrect implementation of such interface, no?
------
      if (usingByteBufferRead == null) {
        if (in instanceof ByteBufferReadable) {
          try {
            n = ((ByteBufferReadable) in).read(inBuffer);
            usingByteBufferRead = Boolean.TRUE;
          } catch (UnsupportedOperationException e) {
            usingByteBufferRead = Boolean.FALSE;
          }
        } else {
          usingByteBufferRead = Boolean.FALSE;
        }
        if (!usingByteBufferRead) {
          n = readFromUnderlyingStream(inBuffer);
        }
      } else {
        if (usingByteBufferRead) {
          n = ((ByteBufferReadable) in).read(inBuffer);
        } else {
          n = readFromUnderlyingStream(inBuffer);
        }
      }
------

If we assume that any {{InputStream}} implementing {{ByteBufferReadable}} supports the {{read(ByteBuffer)}} then the above code could be simplified to:

------
      if (usingByteBufferRead == null) {
        usingByteBufferRead = (in instanceof ByteBufferReadable);
      }
      if (usingByteBufferRead) {
        n = ((ByteBufferReadable) in).read(inBuffer);
      } else {
        n = readFromUnderlyingStream(inBuffer);
      }
------

Or am I missing something obvious?




> NullPointerException in CryptoInputStream while wrapped stream is not ByteBufferReadable. Add tests using normal stream.
> ------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HADOOP-10662
>                 URL: https://issues.apache.org/jira/browse/HADOOP-10662
>             Project: Hadoop Common
>          Issue Type: Sub-task
>          Components: security
>    Affects Versions: fs-encryption (HADOOP-10150 and HDFS-6134)
>            Reporter: Yi Liu
>            Assignee: Yi Liu
>             Fix For: fs-encryption (HADOOP-10150 and HDFS-6134)
>
>         Attachments: HADOOP-10662.patch
>
>
> NullPointerException in CryptoInputStream while wrapped stream is not ByteBufferReadable. 
> Add tests for crypto streams using normal stream which does not support the additional interfaces that the Hadoop FileSystem streams implement (Seekable, PositionedReadable, ByteBufferReadable, HasFileDescriptor, CanSetDropBehind, CanSetReadahead, HasEnhancedByteBufferAccess, Syncable, CanSetDropBehind).



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