Skip to content

Commit

Permalink
ORC-424: Enable findbugs check at test classes
Browse files Browse the repository at this point in the history
Fixes #428

Signed-off-by: Owen O'Malley <omalley@apache.org>
  • Loading branch information
yuokada authored and omalley committed Oct 2, 2019
1 parent 79189d6 commit 1127ba3
Show file tree
Hide file tree
Showing 25 changed files with 505 additions and 478 deletions.
29 changes: 29 additions & 0 deletions java/core/src/findbugs/exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,40 @@
<Bug pattern="MS_PKGPROTECT"/>
<Class name="org.apache.orc.impl.RecordReaderImpl$SargApplier"/>
</Match>
<Match>
<Bug pattern="CNT_ROUGH_CONSTANT_VALUE,IM_BAD_CHECK_FOR_ODD"/>
<Class name="org.apache.orc.TestVectorOrcFile"/>
</Match>
<Match>
<Bug pattern="RR_NOT_CHECKED"/>
<Class name="org.apache.orc.impl.TestInStream"/>
<Method name="testCorruptStream"/>
</Match>
<!-- Java's try with resources causes a false positive.
See https://github.com/SERG-Delft/jpacman/pull/27 . -->
<Match>
<Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"/>
<Class name="org.apache.orc.impl.OrcAcidUtils"/>
<Method name="getLastFlushLength"/>
</Match>
<Match>
<Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"/>
<Class name="org.apache.orc.impl.TestReaderImpl"/>
<Method name="testOptionSafety"/>
</Match>
<Match>
<Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"/>
<Class name="org.apache.orc.TestVectorOrcFile"/>
<Method name="testZstd"/>
</Match>
<Match>
<Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"/>
<Class name="org.apache.orc.impl.TestSchemaEvolution"/>
<Method name="testEvolutionFromTimestamp"/>
</Match>
<Match>
<Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"/>
<Class name="org.apache.orc.impl.TestSchemaEvolution"/>
<Method name="testEvolutionToTimestamp"/>
</Match>
</FindBugsFilter>
18 changes: 10 additions & 8 deletions java/core/src/test/org/apache/orc/TestInMemoryKeystore.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.orc;

import java.nio.charset.StandardCharsets;
import org.apache.hadoop.io.BytesWritable;
import org.apache.orc.impl.HadoopShims;
import org.apache.orc.impl.LocalKey;
Expand Down Expand Up @@ -46,9 +47,9 @@ public void init() throws IOException {
Random random = new Random(2);
memoryKeystore =
new InMemoryKeystore(random)
.addKey("key128", EncryptionAlgorithm.AES_CTR_128, "123".getBytes())
.addKey("key256", EncryptionAlgorithm.AES_CTR_256, "secret123".getBytes())
.addKey("key256short", EncryptionAlgorithm.AES_CTR_256, "5".getBytes());
.addKey("key128", EncryptionAlgorithm.AES_CTR_128, "123".getBytes(StandardCharsets.UTF_8))
.addKey("key256", EncryptionAlgorithm.AES_CTR_256, "secret123".getBytes(StandardCharsets.UTF_8))
.addKey("key256short", EncryptionAlgorithm.AES_CTR_256, "5".getBytes(StandardCharsets.UTF_8));

}

Expand Down Expand Up @@ -134,7 +135,7 @@ public void testRollNewVersion() throws IOException {

Assert.assertEquals(0,
memoryKeystore.getCurrentKeyVersion("key128").getVersion());
memoryKeystore.addKey("key128", 1, EncryptionAlgorithm.AES_CTR_128, "NewSecret".getBytes());
memoryKeystore.addKey("key128", 1, EncryptionAlgorithm.AES_CTR_128, "NewSecret".getBytes(StandardCharsets.UTF_8));
Assert.assertEquals(1,
memoryKeystore.getCurrentKeyVersion("key128").getVersion());
}
Expand All @@ -143,7 +144,7 @@ public void testRollNewVersion() throws IOException {
public void testDuplicateKeyNames() {
try {
memoryKeystore.addKey("key128", 0, EncryptionAlgorithm.AES_CTR_128,
"exception".getBytes());
"exception".getBytes(StandardCharsets.UTF_8));
Assert.fail("Keys with same name cannot be added.");
} catch (IOException e) {
Assert.assertTrue(e.toString().contains("equal or higher version"));
Expand All @@ -162,20 +163,21 @@ public void testDuplicateKeyNames() {
public void testMultipleVersion() throws IOException {
Assert.assertEquals(0,
memoryKeystore.getCurrentKeyVersion("key256").getVersion());
memoryKeystore.addKey("key256", 1, EncryptionAlgorithm.AES_CTR_256, "NewSecret".getBytes());
memoryKeystore.addKey("key256", 1, EncryptionAlgorithm.AES_CTR_256,
"NewSecret".getBytes(StandardCharsets.UTF_8));
Assert.assertEquals(1,
memoryKeystore.getCurrentKeyVersion("key256").getVersion());

try {
memoryKeystore.addKey("key256", 1, EncryptionAlgorithm.AES_CTR_256,
"BadSecret".getBytes());
"BadSecret".getBytes(StandardCharsets.UTF_8));
Assert.fail("Keys with smaller version should not be added.");
} catch (final IOException e) {
Assert.assertTrue(e.toString().contains("equal or higher version"));
}

memoryKeystore.addKey("key256", 2, EncryptionAlgorithm.AES_CTR_256,
"NewerSecret".getBytes());
"NewerSecret".getBytes(StandardCharsets.UTF_8));
Assert.assertEquals(2,
memoryKeystore.getCurrentKeyVersion("key256").getVersion());

Expand Down
8 changes: 0 additions & 8 deletions java/core/src/test/org/apache/orc/TestNewIntegerEncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ public static Collection<Object[]> data() {
return Arrays.asList(data);
}

public static class TSRow {
Timestamp ts;

public TSRow(Timestamp ts) {
this.ts = ts;
}
}

public static TypeDescription getRowSchema() {
return TypeDescription.createStruct()
.addField("int1", TypeDescription.createInt())
Expand Down
3 changes: 0 additions & 3 deletions java/core/src/test/org/apache/orc/TestOrcDSTNoTimezone.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ public static Collection<Object[]> data() {
return result;
}

@Rule
public TestName testCaseName = new TestName();

@Before
public void openFileSystem() throws Exception {
conf = new Configuration();
Expand Down
3 changes: 0 additions & 3 deletions java/core/src/test/org/apache/orc/TestOrcNoTimezone.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ public static Collection<Object[]> data() {
return result;
}

@Rule
public TestName testCaseName = new TestName();

@Before
public void openFileSystem() throws Exception {
conf = new Configuration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Random;

Expand Down Expand Up @@ -80,7 +81,7 @@ void addRow(Writer writer, VectorizedRowBatch batch,
bColumn.noNulls = false;
bColumn.isNull[row] = true;
} else {
bColumn.setVal(row, b.getBytes());
bColumn.setVal(row, b.getBytes(StandardCharsets.UTF_8));
}
if (c == null) {
cColumn.noNulls = false;
Expand Down
14 changes: 7 additions & 7 deletions java/core/src/test/org/apache/orc/TestStringDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void testTooManyDistinct() throws Exception {
writer.addRowBatch(batch);
batch.reset();
}
col.setVal(batch.size++, String.valueOf(i).getBytes());
col.setVal(batch.size++, String.valueOf(i).getBytes(StandardCharsets.UTF_8));
}
writer.addRowBatch(batch);
writer.close();
Expand Down Expand Up @@ -132,7 +132,7 @@ public void testHalfDistinct() throws Exception {
writer.addRowBatch(batch);
batch.reset();
}
col.setVal(batch.size++, String.valueOf(input[i]).getBytes());
col.setVal(batch.size++, String.valueOf(input[i]).getBytes(StandardCharsets.UTF_8));
}
writer.addRowBatch(batch);
writer.close();
Expand Down Expand Up @@ -309,7 +309,7 @@ public void testTooManyDistinctCheckDisabled() throws Exception {
writer.addRowBatch(batch);
batch.reset();
}
string.setVal(batch.size++, String.valueOf(i).getBytes());
string.setVal(batch.size++, String.valueOf(i).getBytes(StandardCharsets.UTF_8));
}
writer.addRowBatch(batch);
writer.close();
Expand Down Expand Up @@ -360,7 +360,7 @@ public void testHalfDistinctCheckDisabled() throws Exception {
writer.addRowBatch(batch);
batch.reset();
}
string.setVal(batch.size++, String.valueOf(input[i]).getBytes());
string.setVal(batch.size++, String.valueOf(input[i]).getBytes(StandardCharsets.UTF_8));
}
writer.addRowBatch(batch);
writer.close();
Expand Down Expand Up @@ -404,7 +404,7 @@ public void testTooManyDistinctV11AlwaysDictionary() throws Exception {
writer.addRowBatch(batch);
batch.reset();
}
string.setVal(batch.size++, String.valueOf(i).getBytes());
string.setVal(batch.size++, String.valueOf(i).getBytes(StandardCharsets.UTF_8));
}
writer.addRowBatch(batch);
writer.close();
Expand Down Expand Up @@ -462,8 +462,8 @@ public void testDisableDictionaryForSpecificColumn() throws Exception {
writer.addRowBatch(batch);
batch.reset();
}
shortStringColumnVector.setVal(batch.size, SHORT_STRING_VALUE.getBytes());
longStringColumnVector.setVal( batch.size, LONG_STRING_VALUE.getBytes());
shortStringColumnVector.setVal(batch.size, SHORT_STRING_VALUE.getBytes(StandardCharsets.UTF_8));
longStringColumnVector.setVal( batch.size, LONG_STRING_VALUE.getBytes(StandardCharsets.UTF_8));
++batch.size;
}
writer.addRowBatch(batch);
Expand Down

0 comments on commit 1127ba3

Please sign in to comment.