Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORC-978: Fix NPE in TestFlinkOrcReaderWriter #891

Merged
merged 2 commits into from Sep 2, 2021

Conversation

guiyanakuang
Copy link
Member

@guiyanakuang guiyanakuang commented Sep 1, 2021

What changes were proposed in this pull request?

This PR aims to fix NPE in TestFlinkOrcReaderWriter.

@Override
  public void close() throws IOException {
    if (!isClosed) {
      try {
        if (batch.size > 0) {
          writer.addRowBatch(batch);
          batch.reset();
        }
      } finally {
        writer.close();
        this.isClosed = true;
      }
    }
  }

writer.addRowBatch(batch);

    .......
      checkMemory();
    } catch (Throwable t) {
      try {
        close();
      } catch (Throwable ignore) {
        // ignore
      }
      if (t instanceof IOException) {
        throw (IOException) t;
      } else {
        throw new IOException("Problem adding row to " + path, t);
      }
    }

addRowBatch method throws java.lang.OutOfMemoryError causing writerImpl to close twice in TestFlinkOrcReaderWriter case.
The first close already set the rawWriter to null, so the second time throw a NullPointerException.

I added status variables to ensure that close will only do the necessary action the first time.

Why are the changes needed?

Fix NPE in TestFlinkOrcReaderWriter.

How was this patch tested?

Add UT for this bug.

@github-actions github-actions bot added the JAVA label Sep 1, 2021
@dongjoon-hyun
Copy link
Member

Thank you so much for working on this, @guiyanakuang .

cc @pgaref , @wgtmac , @williamhyun , @omalley

@@ -118,4 +118,12 @@ public void testStripes() throws Exception {
Reader r = OrcFile.createReader(testFilePath, OrcFile.readerOptions(conf));
assertEquals(r.getStripes(), w.getStripes());
}

@Test
public void testCloseIsIdempotent() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding a test case for this.

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM.
Merged to main/1.7.

@dongjoon-hyun dongjoon-hyun merged commit 8a4e24a into apache:main Sep 2, 2021
dongjoon-hyun pushed a commit that referenced this pull request Sep 2, 2021
### What changes were proposed in this pull request?

This PR aims to fix NPE in TestFlinkOrcReaderWriter.

```java
@OverRide
  public void close() throws IOException {
    if (!isClosed) {
      try {
        if (batch.size > 0) {
          writer.addRowBatch(batch);
          batch.reset();
        }
      } finally {
        writer.close();
        this.isClosed = true;
      }
    }
  }
```

writer.addRowBatch(batch);

```java
    .......
      checkMemory();
    } catch (Throwable t) {
      try {
        close();
      } catch (Throwable ignore) {
        // ignore
      }
      if (t instanceof IOException) {
        throw (IOException) t;
      } else {
        throw new IOException("Problem adding row to " + path, t);
      }
    }
```

addRowBatch method throws java.lang.OutOfMemoryError causing writerImpl to close twice in TestFlinkOrcReaderWriter case.
The first close already set the rawWriter to null, so the second time throw a NullPointerException.

I added status variables to ensure that close will only do the necessary action the first time.

### Why are the changes needed?

Fix NPE in TestFlinkOrcReaderWriter.

### How was this patch tested?

Add UT for this bug.

(cherry picked from commit 8a4e24a)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants