Skip to content

Commit 500654e

Browse files
sraghunandanjackylk
authored andcommitted
[Review][CARBONDATA-1386] fixed findbugs errors in carbondata-core
fixed findbugs errors in carbondata-core This closes apache#1263
1 parent 2ee7775 commit 500654e

File tree

85 files changed

+663
-699
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+663
-699
lines changed

common/src/main/java/org/apache/carbondata/common/logging/impl/ExtendedRollingFileAppender.java

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public boolean accept(File file) {
7474
}
7575
});
7676

77+
if (null == files) {
78+
return;
79+
}
80+
7781
int backupFiles = files.length - 1;
7882

7983
if (backupFiles <= maxBackupIndex) {

core/src/main/java/org/apache/carbondata/core/cache/dictionary/AbstractDictionaryCache.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private CarbonFile getDictionaryMetaCarbonFile(
173173
protected long getSortIndexSize(long numOfRecords) {
174174
// sort index has sort index and reverse sort index,each is 4 byte integer.
175175
// 32 byte is the array header of both the integer arrays
176-
return numOfRecords * ObjectSizeCalculator.estimate(new Integer(0), 16) * 2 + 32;
176+
return numOfRecords * ObjectSizeCalculator.estimate(0, 16) * 2 + 32;
177177
}
178178

179179
/**

core/src/main/java/org/apache/carbondata/core/cache/dictionary/DoubleArrayTrieDictionary.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
*/
3636

3737
public class DoubleArrayTrieDictionary {
38-
public static final byte[] HEAD_MAGIC = new byte[]{
38+
private static final byte[] HEAD_MAGIC = new byte[]{
3939
0x44, 0x41, 0x54, 0x54, 0x72, 0x69, 0x65, 0x44, 0x69, 0x63, 0x74
4040
}; // "DATTrieDict"
41-
public static final int HEAD_LEN = HEAD_MAGIC.length;
41+
private static final int HEAD_LEN = HEAD_MAGIC.length;
4242

4343
private static final int INIT_CAPA_VALUE = 256; // init len of double array
4444
private static final int BASE_ROOT_VALUE = 1; // root base value of trie root
@@ -168,7 +168,7 @@ private TreeSet<Integer> getChildren(int pos) {
168168
return null;
169169
}
170170
if (check[cpos] == pos) {
171-
children.add(new Integer(i));
171+
children.add(i);
172172
}
173173
}
174174
return children;
@@ -227,9 +227,9 @@ private int findAvailableHop(int value) {
227227
private int conflict(int start, int bKey) {
228228
int from = start;
229229
TreeSet<Integer> children = getChildren(from);
230-
children.add(new Integer(bKey));
230+
children.add(bKey);
231231
int newBasePos = findFreeRoom(children);
232-
children.remove(new Integer(bKey));
232+
children.remove(bKey);
233233

234234
int oldBasePos = base[start];
235235
base[start] = newBasePos;
@@ -351,7 +351,7 @@ public void write(DataOutputStream out) throws IOException {
351351
*/
352352
public void read(DataInputStream in) throws IOException {
353353
byte[] header = new byte[HEAD_LEN];
354-
in.read(header);
354+
in.readFully(header);
355355
int comp = 0;
356356
for (int i = 0; i < HEAD_LEN; i++) {
357357
comp = HEAD_MAGIC[i] - header[i];

core/src/main/java/org/apache/carbondata/core/cache/dictionary/ReverseDictionaryCache.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class ReverseDictionaryCache<K extends DictionaryColumnUniqueIdentifier,
5858

5959
private static final long sizeOfHashMapNode = ObjectSizeCalculator.estimate(new
6060
DictionaryByteArrayWrapper(new byte[0]), 16) +
61-
ObjectSizeCalculator.estimate(new Integer(0), 16);
61+
ObjectSizeCalculator.estimate(0, 16);
6262

6363
private static final long byteArraySize = ObjectSizeCalculator.estimate(new byte[0], 16);
6464

core/src/main/java/org/apache/carbondata/core/constants/CarbonCommonConstants.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ public final class CarbonCommonConstants {
189189
/**
190190
* Bytes for string 0, it is used in codegen in case of null values.
191191
*/
192-
public static final byte[] ZERO_BYTE_ARRAY = "0".getBytes();
193-
192+
public static final byte[] ZERO_BYTE_ARRAY = "0".getBytes(Charset.forName(DEFAULT_CHARSET));
194193
/**
195194
* FILE STATUS IN-PROGRESS
196195
*/

core/src/main/java/org/apache/carbondata/core/datamap/DataMapStoreManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public TableDataMap createAndRegisterDataMap(AbsoluteTableIdentifier identifier,
9292
try {
9393
DataMapFactory dataMapFactory = factoryClass.newInstance();
9494
dataMapFactory.init(identifier, dataMapName);
95-
dataMap = new TableDataMap(identifier, dataMapName, dataMapFactory);
95+
dataMap = new TableDataMap(dataMapName, dataMapFactory);
9696
} catch (Exception e) {
9797
LOGGER.error(e);
9898
throw new RuntimeException(e);
@@ -119,7 +119,7 @@ private TableDataMap getAbstractTableDataMap(String dataMapName,
119119
* @param dataMapName
120120
*/
121121
public void clearDataMap(AbsoluteTableIdentifier identifier, String dataMapName) {
122-
List<TableDataMap> tableDataMaps = allDataMaps.get(identifier);
122+
List<TableDataMap> tableDataMaps = allDataMaps.get(identifier.uniqueName());
123123
if (tableDataMaps != null) {
124124
int i = 0;
125125
for (TableDataMap tableDataMap: tableDataMaps) {

core/src/main/java/org/apache/carbondata/core/datamap/TableDataMap.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.apache.carbondata.core.events.ChangeEvent;
2626
import org.apache.carbondata.core.events.EventListener;
2727
import org.apache.carbondata.core.indexstore.Blocklet;
28-
import org.apache.carbondata.core.metadata.AbsoluteTableIdentifier;
2928
import org.apache.carbondata.core.scan.filter.resolver.FilterResolverIntf;
3029

3130
/**
@@ -34,18 +33,15 @@
3433
*/
3534
public final class TableDataMap implements EventListener {
3635

37-
private AbsoluteTableIdentifier identifier;
38-
3936
private String dataMapName;
4037

4138
private DataMapFactory dataMapFactory;
4239

4340
/**
4441
* It is called to initialize and load the required table datamap metadata.
4542
*/
46-
public TableDataMap(AbsoluteTableIdentifier identifier, String dataMapName,
43+
public TableDataMap(String dataMapName,
4744
DataMapFactory dataMapFactory) {
48-
this.identifier = identifier;
4945
this.dataMapName = dataMapName;
5046
this.dataMapFactory = dataMapFactory;
5147
}

core/src/main/java/org/apache/carbondata/core/datastore/AbstractBlockIndexStoreCache.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@
4141
*/
4242
public abstract class AbstractBlockIndexStoreCache<K, V>
4343
implements Cache<TableBlockUniqueIdentifier, AbstractIndex> {
44-
/**
45-
* carbon store path
46-
*/
47-
protected String carbonStorePath;
44+
4845
/**
4946
* CarbonLRU cache
5047
*/
@@ -70,8 +67,7 @@ public abstract class AbstractBlockIndexStoreCache<K, V>
7067
*/
7168
protected Map<String, Object> segmentIDLock;
7269

73-
public AbstractBlockIndexStoreCache(String carbonStorePath, CarbonLRUCache lruCache) {
74-
this.carbonStorePath = carbonStorePath;
70+
public AbstractBlockIndexStoreCache(CarbonLRUCache lruCache) {
7571
this.lruCache = lruCache;
7672
blockInfoLock = new ConcurrentHashMap<BlockInfo, Object>();
7773
segmentIDLock = new ConcurrentHashMap<String, Object>();

core/src/main/java/org/apache/carbondata/core/datastore/BlockIndexStore.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class BlockIndexStore<K, V> extends AbstractBlockIndexStoreCache<K, V> {
5959
private static final LogService LOGGER =
6060
LogServiceFactory.getLogService(BlockIndexStore.class.getName());
6161
public BlockIndexStore(String carbonStorePath, CarbonLRUCache lruCache) {
62-
super(carbonStorePath, lruCache);
62+
super(lruCache);
6363
}
6464

6565
/**

core/src/main/java/org/apache/carbondata/core/datastore/block/TableBlockInfo.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,15 @@ public long getBlockLength() {
190190
if (blockLength != other.blockLength) {
191191
return false;
192192
}
193-
if (filePath == null && other.filePath != null) {
194-
return false;
195-
} else if (filePath != null && other.filePath == null) {
196-
return false;
197-
} else if (!filePath.equals(other.filePath)) {
193+
194+
if (null == filePath || null == other.filePath) {
195+
return false;
196+
}
197+
198+
if (!filePath.equals(other.filePath)) {
198199
return false;
199200
}
201+
200202
if (blockletInfos.getStartBlockletNumber() != other.blockletInfos.getStartBlockletNumber()) {
201203
return false;
202204
}

core/src/main/java/org/apache/carbondata/core/datastore/block/TableTaskInfo.java

+23
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,29 @@ public TableTaskInfo(String taskId, List<TableBlockInfo> tableBlockInfoList) {
6060
return taskId.compareTo(((TableTaskInfo)o).getTaskId());
6161
}
6262

63+
@Override public boolean equals(Object obj) {
64+
if (this == obj) {
65+
return true;
66+
}
67+
68+
if (null == obj) {
69+
return false;
70+
}
71+
72+
if (!(obj instanceof TableTaskInfo)) {
73+
return false;
74+
}
75+
76+
return 0 == taskId.compareTo(((TableTaskInfo)obj).getTaskId());
77+
}
78+
79+
@Override public int hashCode() {
80+
final int prime = 31;
81+
int result = 1;
82+
result = prime * result + ((taskId == null) ? 0 : taskId.hashCode());
83+
return result;
84+
}
85+
6386
/**
6487
* Finding which node has the maximum number of blocks for it.
6588
* @param blockList

core/src/main/java/org/apache/carbondata/core/datastore/chunk/impl/FixedLengthDimensionDataChunk.java

+8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ public FixedLengthDimensionDataChunk(byte[] dataChunk, int[] invertedIndex,
110110
case LONG:
111111
vector.putLong(vectorOffset++, (long) valueFromSurrogate);
112112
break;
113+
default:
114+
throw new IllegalArgumentException(
115+
"unsupported data type: " + columnVectorInfo.directDictionaryGenerator
116+
.getReturnType());
113117
}
114118
}
115119
}
@@ -150,6 +154,10 @@ public FixedLengthDimensionDataChunk(byte[] dataChunk, int[] invertedIndex,
150154
case LONG:
151155
vector.putLong(vectorOffset++, (long) valueFromSurrogate);
152156
break;
157+
default:
158+
throw new IllegalArgumentException(
159+
"unsupported data type: " + columnVectorInfo.directDictionaryGenerator
160+
.getReturnType());
153161
}
154162
}
155163
}

core/src/main/java/org/apache/carbondata/core/datastore/chunk/store/impl/unsafe/UnsafeAbstractDimensionDataChunkStore.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@ public UnsafeAbstractDimensionDataChunkStore(long totalSize, boolean isInvertedI
9292
invertedIndex.length * CarbonCommonConstants.INT_SIZE_IN_BYTE;
9393
}
9494
// copy the data to memory
95-
CarbonUnsafe.unsafe
95+
CarbonUnsafe.getUnsafe()
9696
.copyMemory(data, CarbonUnsafe.BYTE_ARRAY_OFFSET, dataPageMemoryBlock.getBaseObject(),
9797
dataPageMemoryBlock.getBaseOffset(), this.dataLength);
9898
// if inverted index is present then copy the inverted index
9999
// and reverse inverted index to memory
100100
if (isExplicitSorted) {
101-
CarbonUnsafe.unsafe.copyMemory(invertedIndex, CarbonUnsafe.INT_ARRAY_OFFSET,
101+
CarbonUnsafe.getUnsafe().copyMemory(invertedIndex, CarbonUnsafe.INT_ARRAY_OFFSET,
102102
dataPageMemoryBlock.getBaseObject(), dataPageMemoryBlock.getBaseOffset() + dataLength,
103103
invertedIndex.length * CarbonCommonConstants.INT_SIZE_IN_BYTE);
104-
CarbonUnsafe.unsafe.copyMemory(invertedIndexReverse, CarbonUnsafe.INT_ARRAY_OFFSET,
104+
CarbonUnsafe.getUnsafe().copyMemory(invertedIndexReverse, CarbonUnsafe.INT_ARRAY_OFFSET,
105105
dataPageMemoryBlock.getBaseObject(),
106106
dataPageMemoryBlock.getBaseOffset() + this.invertedIndexReverseOffset,
107107
invertedIndexReverse.length * CarbonCommonConstants.INT_SIZE_IN_BYTE);
@@ -129,8 +129,8 @@ public UnsafeAbstractDimensionDataChunkStore(long totalSize, boolean isInvertedI
129129
* @return inverted index based on row id passed
130130
*/
131131
@Override public int getInvertedIndex(int rowId) {
132-
return CarbonUnsafe.unsafe.getInt(dataPageMemoryBlock.getBaseObject(),
133-
dataPageMemoryBlock.getBaseOffset() + dataLength + (rowId
132+
return CarbonUnsafe.getUnsafe().getInt(dataPageMemoryBlock.getBaseObject(),
133+
dataPageMemoryBlock.getBaseOffset() + dataLength + ((long)rowId
134134
* CarbonCommonConstants.INT_SIZE_IN_BYTE));
135135
}
136136

core/src/main/java/org/apache/carbondata/core/datastore/chunk/store/impl/unsafe/UnsafeFixedLengthDimensionDataChunkStore.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ public UnsafeFixedLengthDimensionDataChunkStore(long totalDataSize, int columnVa
5353
@Override public byte[] getRow(int rowId) {
5454
// if column was explicitly sorted we need to get the rowid based inverted index reverse
5555
if (isExplicitSorted) {
56-
rowId = CarbonUnsafe.unsafe.getInt(dataPageMemoryBlock.getBaseObject(),
57-
dataPageMemoryBlock.getBaseOffset() + this.invertedIndexReverseOffset + (rowId
56+
rowId = CarbonUnsafe.getUnsafe().getInt(dataPageMemoryBlock.getBaseObject(),
57+
dataPageMemoryBlock.getBaseOffset() + this.invertedIndexReverseOffset + ((long)rowId
5858
* CarbonCommonConstants.INT_SIZE_IN_BYTE));
5959
}
6060
// creating a row
6161
byte[] data = new byte[columnValueSize];
6262
//copy the row from memory block based on offset
6363
// offset position will be index * each column value length
64-
CarbonUnsafe.unsafe.copyMemory(dataPageMemoryBlock.getBaseObject(),
65-
dataPageMemoryBlock.getBaseOffset() + (rowId * columnValueSize), data,
64+
CarbonUnsafe.getUnsafe().copyMemory(dataPageMemoryBlock.getBaseObject(),
65+
dataPageMemoryBlock.getBaseOffset() + ((long)rowId * columnValueSize), data,
6666
CarbonUnsafe.BYTE_ARRAY_OFFSET, columnValueSize);
6767
return data;
6868
}
@@ -77,16 +77,16 @@ public UnsafeFixedLengthDimensionDataChunkStore(long totalDataSize, int columnVa
7777
@Override public int getSurrogate(int index) {
7878
// if column was explicitly sorted we need to get the rowid based inverted index reverse
7979
if (isExplicitSorted) {
80-
index = CarbonUnsafe.unsafe.getInt(dataPageMemoryBlock.getBaseObject(),
81-
dataPageMemoryBlock.getBaseOffset() + this.invertedIndexReverseOffset + (index
80+
index = CarbonUnsafe.getUnsafe().getInt(dataPageMemoryBlock.getBaseObject(),
81+
dataPageMemoryBlock.getBaseOffset() + this.invertedIndexReverseOffset + ((long)index
8282
* CarbonCommonConstants.INT_SIZE_IN_BYTE));
8383
}
8484
// below part is to convert the byte array to surrogate value
8585
int startOffsetOfData = index * columnValueSize;
8686
int surrogate = 0;
8787
for (int i = 0; i < columnValueSize; i++) {
8888
surrogate <<= 8;
89-
surrogate ^= CarbonUnsafe.unsafe.getByte(dataPageMemoryBlock.getBaseObject(),
89+
surrogate ^= CarbonUnsafe.getUnsafe().getByte(dataPageMemoryBlock.getBaseObject(),
9090
dataPageMemoryBlock.getBaseOffset() + startOffsetOfData) & 0xFF;
9191
startOffsetOfData++;
9292
}
@@ -103,14 +103,14 @@ public UnsafeFixedLengthDimensionDataChunkStore(long totalDataSize, int columnVa
103103
@Override public void fillRow(int rowId, byte[] buffer, int offset) {
104104
// if column was explicitly sorted we need to get the rowid based inverted index reverse
105105
if (isExplicitSorted) {
106-
rowId = CarbonUnsafe.unsafe.getInt(dataPageMemoryBlock.getBaseObject(),
107-
dataPageMemoryBlock.getBaseOffset() + this.invertedIndexReverseOffset + (rowId
106+
rowId = CarbonUnsafe.getUnsafe().getInt(dataPageMemoryBlock.getBaseObject(),
107+
dataPageMemoryBlock.getBaseOffset() + this.invertedIndexReverseOffset + ((long)rowId
108108
* CarbonCommonConstants.INT_SIZE_IN_BYTE));
109109
}
110110
//copy the row from memory block based on offset
111111
// offset position will be index * each column value length
112-
CarbonUnsafe.unsafe.copyMemory(dataPageMemoryBlock.getBaseObject(),
113-
dataPageMemoryBlock.getBaseOffset() + (rowId * columnValueSize), buffer,
112+
CarbonUnsafe.getUnsafe().copyMemory(dataPageMemoryBlock.getBaseObject(),
113+
dataPageMemoryBlock.getBaseOffset() + ((long)rowId * columnValueSize), buffer,
114114
CarbonUnsafe.BYTE_ARRAY_OFFSET + offset, columnValueSize);
115115
}
116116

@@ -133,7 +133,7 @@ public UnsafeFixedLengthDimensionDataChunkStore(long totalDataSize, int columnVa
133133
index = index * columnValueSize;
134134
int compareResult = 0;
135135
for (int i = 0; i < compareValue.length; i++) {
136-
compareResult = (CarbonUnsafe.unsafe
136+
compareResult = (CarbonUnsafe.getUnsafe()
137137
.getByte(dataPageMemoryBlock.getBaseObject(), dataPageMemoryBlock.getBaseOffset() + index)
138138
& 0xff) - (compareValue[i] & 0xff);
139139
if (compareResult != 0) {

0 commit comments

Comments
 (0)