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

[WIP] ORC-424: Add findbugs checks for test classes #428

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 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,7 +47,7 @@ public void init() throws IOException {
Random random = new Random(2);
memoryKeystore =
new InMemoryKeystore(random)
.addKey("key128", EncryptionAlgorithm.AES_CTR_128, "123".getBytes())
.addKey("key128", EncryptionAlgorithm.AES_CTR_128, "123".getBytes(StandardCharsets.UTF_8))
.addKey("key256", EncryptionAlgorithm.AES_CTR_256, "secret123".getBytes())
.addKey("key256short", EncryptionAlgorithm.AES_CTR_256, "5".getBytes());

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,7 +163,7 @@ 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());

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
12 changes: 6 additions & 6 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,7 +462,7 @@ public void testDisableDictionaryForSpecificColumn() throws Exception {
writer.addRowBatch(batch);
batch.reset();
}
shortStringColumnVector.setVal(batch.size, SHORT_STRING_VALUE.getBytes());
shortStringColumnVector.setVal(batch.size, SHORT_STRING_VALUE.getBytes(StandardCharsets.UTF_8));
longStringColumnVector.setVal( batch.size, LONG_STRING_VALUE.getBytes());
++batch.size;
}
Expand Down
36 changes: 18 additions & 18 deletions java/core/src/test/org/apache/orc/TestVectorOrcFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public void testStringAndBinaryStatistics() throws Exception {
field1.setVal(2, bytesArray(0, 1, 2, 3, 4, 5));
field1.noNulls = false;
field1.isNull[3] = true;
field2.setVal(0, "foo".getBytes());
field2.setVal(0, "foo".getBytes(StandardCharsets.UTF_8));
field2.setVal(1, "bar".getBytes());
field2.noNulls = false;
field2.isNull[2] = true;
Expand Down Expand Up @@ -577,7 +577,7 @@ public void testStripeLevelStats() throws Exception {
if (b >= 5) {
if (b >= 10) {
field1.vector[0] = 3;
field2.setVal(0, "three".getBytes());
field2.setVal(0, "three".getBytes(StandardCharsets.UTF_8));
} else {
field1.vector[0] = 2;
field2.setVal(0, "two".getBytes());
Expand Down Expand Up @@ -658,7 +658,7 @@ private static void setInner(StructColumnVector inner, int rowId,
int i, String value) {
((LongColumnVector) inner.fields[0]).vector[rowId] = i;
if (value != null) {
((BytesColumnVector) inner.fields[1]).setVal(rowId, value.getBytes());
((BytesColumnVector) inner.fields[1]).setVal(rowId, value.getBytes(StandardCharsets.UTF_8));
} else {
inner.fields[1].isNull[rowId] = true;
inner.fields[1].noNulls = false;
Expand Down Expand Up @@ -727,7 +727,7 @@ private static void setInnerMap(MapColumnVector map, int rowId,
map.offsets[rowId] = offset;

for (Map.Entry<String, InnerStruct> entry : value.entrySet()) {
((BytesColumnVector) map.keys).setVal(offset, entry.getKey().getBytes());
((BytesColumnVector) map.keys).setVal(offset, entry.getKey().getBytes(StandardCharsets.UTF_8));
InnerStruct inner = entry.getValue();
setInner((StructColumnVector) map.values, offset, inner.int1,
inner.string1.toString());
Expand Down Expand Up @@ -800,7 +800,7 @@ private static void setBigRow(VectorizedRowBatch batch, int rowId,
batch.cols[7].noNulls = false;
}
if (s2 != null) {
((BytesColumnVector) batch.cols[8]).setVal(rowId, s2.getBytes());
((BytesColumnVector) batch.cols[8]).setVal(rowId, s2.getBytes(StandardCharsets.UTF_8));
} else {
batch.cols[8].isNull[rowId] = true;
batch.cols[8].noNulls = false;
Expand Down Expand Up @@ -1260,7 +1260,7 @@ public void testColumnProjection() throws Exception {
}
first = false;
((LongColumnVector) batch.cols[0]).vector[r] = x;
((BytesColumnVector) batch.cols[1]).setVal(r, y.getBytes());
((BytesColumnVector) batch.cols[1]).setVal(r, y.getBytes(StandardCharsets.UTF_8));
}
writer.addRowBatch(batch);
}
Expand Down Expand Up @@ -1500,7 +1500,7 @@ private static void setUnion(VectorizedRowBatch batch, int rowId,
}
} else if (tag == 1) {
if (s != null) {
((BytesColumnVector) union.fields[tag]).setVal(rowId, s.getBytes());
((BytesColumnVector) union.fields[tag]).setVal(rowId, s.getBytes(StandardCharsets.UTF_8));
} else {
union.fields[tag].isNull[rowId] = true;
union.fields[tag].noNulls = false;
Expand Down Expand Up @@ -2232,7 +2232,7 @@ private void writeRandomIntBytesBatches(
for (int r=0; r < size; ++r) {
((LongColumnVector) batch.cols[0]).vector[r] = rand.nextInt();
((BytesColumnVector) batch.cols[1]).setVal(r,
Integer.toHexString(rand.nextInt()).getBytes());
Integer.toHexString(rand.nextInt()).getBytes(StandardCharsets.UTF_8));
}
writer.addRowBatch(batch);
}
Expand Down Expand Up @@ -2262,7 +2262,7 @@ public void testWithoutIndex() throws Exception {
for(int i=0; i < 10000; ++i) {
((LongColumnVector) batch.cols[0]).vector[0] = rand.nextInt();
((BytesColumnVector) batch.cols[1])
.setVal(0, Integer.toBinaryString(rand.nextInt()).getBytes());
.setVal(0, Integer.toBinaryString(rand.nextInt()).getBytes(StandardCharsets.UTF_8));
writer.addRowBatch(batch);
}
writer.close();
Expand Down Expand Up @@ -2505,7 +2505,7 @@ public void testMemoryManagementV11() throws Exception {
for(int i=0; i < 2500; ++i) {
((LongColumnVector) batch.cols[0]).vector[0] = i * 300;
((BytesColumnVector) batch.cols[1]).setVal(0,
Integer.toHexString(10*i).getBytes());
Integer.toHexString(10*i).getBytes(StandardCharsets.UTF_8));
writer.addRowBatch(batch);
}
writer.close();
Expand Down Expand Up @@ -2542,7 +2542,7 @@ public void testMemoryManagementV12() throws Exception {
for(int i=0; i < 2500; ++i) {
((LongColumnVector) batch.cols[0]).vector[0] = i * 300;
((BytesColumnVector) batch.cols[1]).setVal(0,
Integer.toHexString(10*i).getBytes());
Integer.toHexString(10*i).getBytes(StandardCharsets.UTF_8));
writer.addRowBatch(batch);
}
writer.close();
Expand Down Expand Up @@ -2579,7 +2579,7 @@ public void testPredicatePushdown() throws Exception {
for(int i=0; i < 3500; ++i) {
((LongColumnVector) batch.cols[0]).vector[i] = i * 300;
((BytesColumnVector) batch.cols[1]).setVal(i,
Integer.toHexString(10*i).getBytes());
Integer.toHexString(10*i).getBytes(StandardCharsets.UTF_8));
}
writer.addRowBatch(batch);
writer.close();
Expand Down Expand Up @@ -2713,7 +2713,7 @@ public void testRepeating() throws Exception {
for(int c =0; c < batch.cols.length; ++c) {
batch.cols[c].isNull[0] = false;
}
((BytesColumnVector) batch.cols[0]).setVal(0, "Horton".getBytes());
((BytesColumnVector) batch.cols[0]).setVal(0, "Horton".getBytes(StandardCharsets.UTF_8));
((LongColumnVector) batch.cols[1]).vector[0] = 1;
((LongColumnVector) batch.cols[2]).vector[0] = 130;
((LongColumnVector) batch.cols[3]).vector[0] = 0x123456789abcdef0L;
Expand Down Expand Up @@ -2974,7 +2974,7 @@ private static String makeString(BytesColumnVector vector, int row) {
}
if (vector.noNulls || !vector.isNull[row]) {
return new String(vector.vector[row], vector.start[row],
vector.length[row]);
vector.length[row], StandardCharsets.UTF_8);
} else {
return null;
}
Expand All @@ -2994,7 +2994,7 @@ public void testStringPadding() throws Exception {
VectorizedRowBatch batch = schema.createRowBatch();
batch.size = 4;
for(int c=0; c < batch.cols.length; ++c) {
((BytesColumnVector) batch.cols[c]).setVal(0, "".getBytes());
((BytesColumnVector) batch.cols[c]).setVal(0, "".getBytes(StandardCharsets.UTF_8));
((BytesColumnVector) batch.cols[c]).setVal(1, "xyz".getBytes());
((BytesColumnVector) batch.cols[c]).setVal(2, "0123456789".getBytes());
((BytesColumnVector) batch.cols[c]).setVal(3,
Expand Down Expand Up @@ -3047,7 +3047,7 @@ public void testNonDictionaryRepeatingString() throws Exception {
batch.size = 1024;
for(int r=0; r < batch.size; ++r) {
((BytesColumnVector) batch.cols[0]).setVal(r,
Integer.toString(r * 10001).getBytes());
Integer.toString(r * 10001).getBytes(StandardCharsets.UTF_8));
}
writer.addRowBatch(batch);
batch.cols[0].isRepeating = true;
Expand Down Expand Up @@ -3360,7 +3360,7 @@ public void testExpansion() throws Exception {
list2.offsets[1] = 2000;
list2.lengths[1] = 3000;
for(int v=0; v < 5000; ++v) {
byte[] bytes = Long.toHexString(v).getBytes();
byte[] bytes = Long.toHexString(v).getBytes(StandardCharsets.UTF_8);
str.setVal(v, bytes);
bin.setVal(v, bytes);
}
Expand Down Expand Up @@ -3984,7 +3984,7 @@ public void testPredicatePushdownForComplex() throws Exception {
((LongColumnVector) batch.cols[0]).vector[i] = i;
((LongColumnVector)((StructColumnVector) batch.cols[1]).fields[0]).vector[i] = i * 300;
((BytesColumnVector)((StructColumnVector) batch.cols[1]).fields[1]).setVal(i,
Integer.toHexString(10*i).getBytes());
Integer.toHexString(10*i).getBytes(StandardCharsets.UTF_8));
}
writer.addRowBatch(batch);
writer.close();
Expand Down
12 changes: 5 additions & 7 deletions java/core/src/test/org/apache/orc/impl/TestInStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

package org.apache.orc.impl;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
Expand All @@ -26,7 +29,7 @@
import java.security.Key;
import java.util.ArrayList;
import java.util.List;

import javax.crypto.spec.SecretKeySpec;
import org.apache.hadoop.hive.common.io.DiskRangeList;
import org.apache.orc.CompressionCodec;
import org.apache.orc.EncryptionAlgorithm;
Expand All @@ -35,11 +38,6 @@
import org.apache.orc.impl.writer.StreamOptions;
import org.junit.Test;

import javax.crypto.spec.SecretKeySpec;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

public class TestInStream {

public static class OutputCollector implements PhysicalWriter.OutputReceiver {
Expand Down Expand Up @@ -176,7 +174,7 @@ static byte[] getEncrypted(PositionCollector[] positions,
}
out.flush();
byte[] result = collect.buffer.get();
assertEquals(ROW_COUNT * 8, result.length);
assertEquals(ROW_COUNT * 8L, result.length);
return result;
}

Expand Down
25 changes: 12 additions & 13 deletions java/core/src/test/org/apache/orc/impl/TestOutStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@

package org.apache.orc.impl;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.orc.CompressionCodec;
import org.apache.orc.EncryptionAlgorithm;
import org.apache.orc.InMemoryKeystore;
Expand All @@ -28,18 +39,6 @@
import org.junit.Test;
import org.mockito.Mockito;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.Key;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

public class TestOutStream {

@Test
Expand Down Expand Up @@ -208,7 +207,7 @@ public void testCompression256Encryption() throws Exception {

// check the contents of the decompressed stream
BufferedReader reader
= new BufferedReader(new InputStreamReader(decompressedStream));
= new BufferedReader(new InputStreamReader(decompressedStream, StandardCharsets.UTF_8));
for(int i=0; i < 10000; ++i) {
assertEquals("i = " + i, "The Cheesy Poofs " + i, reader.readLine());
}
Expand Down