fix CodeQL security reports, update to Java 17, fix Java 17 warnings

main 2.0.0
Jörg Prante 2 years ago
parent 91c585b465
commit 20762770b1

@ -1,6 +1,5 @@
package org.xbib.datastructures.common; package org.xbib.datastructures.common;
import org.xbib.datastructures.common.StrictArraySet;
import java.util.AbstractMap; import java.util.AbstractMap;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
@ -77,7 +76,7 @@ public class StrictArrayMap<K, V> extends AbstractMap<K, V> implements Map<K, V>
public V get(Object key) { public V get(Object key) {
for (int i = 0; i < keys.length; i++ ) { for (int i = 0; i < keys.length; i++ ) {
if (keys[i].equals(key)) { if (keys[i].equals(key)) {
return (V) values[i]; return values[i];
} }
} }
return null; return null;
@ -113,10 +112,10 @@ public class StrictArrayMap<K, V> extends AbstractMap<K, V> implements Map<K, V>
return new StrictArraySet<>(values); return new StrictArraySet<>(values);
} }
@SuppressWarnings("unchecked") @SuppressWarnings({"unchecked", "rawtypes"})
@Override @Override
public Set<Entry<K, V>> entrySet() { public Set<Entry<K, V>> entrySet() {
Entry<K, V>[] entries = new Map.Entry[keys.length]; Map.Entry<K, V>[] entries = new Map.Entry[keys.length];
for (int i = 0; i < keys.length; i++) { for (int i = 0; i < keys.length; i++) {
entries[i] = new EntryHolder<>(keys[i], values[i]); entries[i] = new EntryHolder<>(keys[i], values[i]);
} }

@ -2,6 +2,9 @@ package org.xbib.datastructures.common;
public class Utf8Util { public class Utf8Util {
public Utf8Util() {
}
public static String decode(byte[] data, int offset, int length) { public static String decode(byte[] data, int offset, int length) {
char[] chars = new char[length]; char[] chars = new char[length];
int len = 0; int len = 0;

@ -247,10 +247,10 @@ public class TestJSONParser {
ret += parser.getNumberChars().length(); ret += parser.getNumberChars().length();
break; break;
case JSONParser.NUMBER: case JSONParser.NUMBER:
ret += parser.getDouble(); ret = ret + (int)parser.getDouble();
break; break;
case JSONParser.LONG: case JSONParser.LONG:
ret += parser.getLong(); ret = ret + (int)parser.getLong();
break; break;
default: default:
ret += ev; ret += ev;

@ -135,7 +135,7 @@ public class TestPerf {
ret += parser.getNumberChars().length(); ret += parser.getNumberChars().length();
break; break;
case JSONParser.NUMBER: case JSONParser.NUMBER:
ret += Double.doubleToRawLongBits(parser.getDouble()); ret = ret + (int)Double.doubleToRawLongBits(parser.getDouble());
break; break;
case JSONParser.ARRAY_START: case JSONParser.ARRAY_START:
ret += 13; ret += 13;

@ -6,6 +6,9 @@ import java.util.Deque;
public class EmptyJsonListener implements JsonResult { public class EmptyJsonListener implements JsonResult {
public EmptyJsonListener() {
}
@Override @Override
public void begin() { public void begin() {
} }

@ -156,7 +156,7 @@ public class FastDoubleParser {
if (neg_exp) { if (neg_exp) {
exp_number = -exp_number; exp_number = -exp_number;
} }
exponent += exp_number; exponent = exponent + (int)exp_number;
} }
index = skipWhitespace(str, index, endIndex); index = skipWhitespace(str, index, endIndex);
if (index < endIndex if (index < endIndex
@ -164,7 +164,7 @@ public class FastDoubleParser {
throw newNumberFormatException(str); throw newNumberFormatException(str);
} }
final boolean isDigitsTruncated; final boolean isDigitsTruncated;
int skipCountInTruncatedDigits = 0;//counts +1 if we skipped over the decimal point int skipCountInTruncatedDigits = 0;
if (digitCount > 19) { if (digitCount > 19) {
digits = 0; digits = 0;
for (index = indexOfFirstDigit; index < indexAfterDigits; index++) { for (index = indexOfFirstDigit; index < indexAfterDigits; index++) {
@ -231,10 +231,7 @@ public class FastDoubleParser {
if (index >= endIndex) { if (index >= endIndex) {
throw newNumberFormatException(str); throw newNumberFormatException(str);
} }
long digits = 0;
// Parse digits
// ------------
long digits = 0;// digits is treated as an unsigned long
int exponent = 0; int exponent = 0;
final int indexOfFirstDigit = index; final int indexOfFirstDigit = index;
int virtualIndexOfPoint = -1; int virtualIndexOfPoint = -1;
@ -242,10 +239,9 @@ public class FastDoubleParser {
char ch = 0; char ch = 0;
for (; index < endIndex; index++) { for (; index < endIndex; index++) {
ch = str.charAt(index); ch = str.charAt(index);
// Table look up is faster than a sequence of if-else-branches.
int hexValue = ch > 255 ? OTHER_CLASS : CHAR_TO_HEX_MAP[ch]; int hexValue = ch > 255 ? OTHER_CLASS : CHAR_TO_HEX_MAP[ch];
if (hexValue >= 0) { if (hexValue >= 0) {
digits = (digits << 4) | hexValue;// This might overflow, we deal with it later. digits = (digits << 4) | hexValue;
} else if (hexValue == DECIMAL_POINT_CLASS) { } else if (hexValue == DECIMAL_POINT_CLASS) {
if (virtualIndexOfPoint != -1) { if (virtualIndexOfPoint != -1) {
throw newNumberFormatException(str); throw newNumberFormatException(str);
@ -263,9 +259,6 @@ public class FastDoubleParser {
digitCount = indexAfterDigits - indexOfFirstDigit - 1; digitCount = indexAfterDigits - indexOfFirstDigit - 1;
exponent = Math.min(virtualIndexOfPoint - index + 1, MINIMAL_EIGHT_DIGIT_INTEGER) * 4; exponent = Math.min(virtualIndexOfPoint - index + 1, MINIMAL_EIGHT_DIGIT_INTEGER) * 4;
} }
// Parse exponent number
// ---------------------
long exp_number = 0; long exp_number = 0;
final boolean hasExponent = (ch == 'p') || (ch == 'P'); final boolean hasExponent = (ch == 'p') || (ch == 'P');
if (hasExponent) { if (hasExponent) {
@ -278,7 +271,6 @@ public class FastDoubleParser {
throw newNumberFormatException(str); throw newNumberFormatException(str);
} }
do { do {
// Guard against overflow of exp_number
if (exp_number < MINIMAL_EIGHT_DIGIT_INTEGER) { if (exp_number < MINIMAL_EIGHT_DIGIT_INTEGER) {
exp_number = 10 * exp_number + ch - '0'; exp_number = 10 * exp_number + ch - '0';
} }
@ -287,27 +279,20 @@ public class FastDoubleParser {
if (neg_exp) { if (neg_exp) {
exp_number = -exp_number; exp_number = -exp_number;
} }
exponent += exp_number; exponent = exponent + (int)exp_number;
} }
// Skip trailing whitespace
// ------------------------
index = skipWhitespace(str, index, endIndex); index = skipWhitespace(str, index, endIndex);
if (index < endIndex if (index < endIndex
|| digitCount == 0 && str.charAt(virtualIndexOfPoint) != '.' || digitCount == 0 && str.charAt(virtualIndexOfPoint) != '.'
|| !hasExponent) { || !hasExponent) {
throw newNumberFormatException(str); throw newNumberFormatException(str);
} }
// Re-parse digits in case of a potential overflow
// -----------------------------------------------
final boolean isDigitsTruncated; final boolean isDigitsTruncated;
int skipCountInTruncatedDigits = 0;//counts +1 if we skipped over the decimal point int skipCountInTruncatedDigits = 0;
if (digitCount > 16) { if (digitCount > 16) {
digits = 0; digits = 0;
for (index = indexOfFirstDigit; index < indexAfterDigits; index++) { for (index = indexOfFirstDigit; index < indexAfterDigits; index++) {
ch = str.charAt(index); ch = str.charAt(index);
// Table look up is faster than a sequence of if-else-branches.
int hexValue = ch > 127 ? OTHER_CLASS : CHAR_TO_HEX_MAP[ch]; int hexValue = ch > 127 ? OTHER_CLASS : CHAR_TO_HEX_MAP[ch];
if (hexValue >= 0) { if (hexValue >= 0) {
if (Long.compareUnsigned(digits, MINIMAL_NINETEEN_DIGIT_INTEGER) < 0) { if (Long.compareUnsigned(digits, MINIMAL_NINETEEN_DIGIT_INTEGER) < 0) {

@ -6,6 +6,9 @@ import java.util.List;
public class ListNode extends TinyList.Builder<Node<?>> implements org.xbib.datastructures.api.ListNode { public class ListNode extends TinyList.Builder<Node<?>> implements org.xbib.datastructures.api.ListNode {
public ListNode() {
}
public boolean has(int i) { public boolean has(int i) {
return i >= 0 && i < size() && get(i) == null; return i >= 0 && i < size() && get(i) == null;
} }

@ -6,6 +6,9 @@ import java.util.Map;
public class MapNode extends TinyMap.Builder<CharSequence, Node<?>> implements org.xbib.datastructures.api.MapNode { public class MapNode extends TinyMap.Builder<CharSequence, Node<?>> implements org.xbib.datastructures.api.MapNode {
public MapNode() {
}
public boolean has(String name) { public boolean has(String name) {
return containsKey(name); return containsKey(name);
} }

@ -17,6 +17,9 @@ public class StandardJsonListener implements JsonResult {
private final ValueNode FALSE_NODE = new ValueNode(Boolean.FALSE); private final ValueNode FALSE_NODE = new ValueNode(Boolean.FALSE);
public StandardJsonListener() {
}
public Deque<Node<?>> getStack() { public Deque<Node<?>> getStack() {
return stack; return stack;
} }

@ -8,6 +8,9 @@ import java.util.List;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class StandardListNode extends ArrayList<Object> implements Node<List<Object>> { public class StandardListNode extends ArrayList<Object> implements Node<List<Object>> {
public StandardListNode() {
}
public boolean has(int i) { public boolean has(int i) {
return i >= 0 && i < size() && get(i) == null; return i >= 0 && i < size() && get(i) == null;
} }

@ -8,6 +8,9 @@ import java.util.Map;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class StandardMapNode extends LinkedHashMap<CharSequence, Object> implements Node<Map<CharSequence, Object>> { public class StandardMapNode extends LinkedHashMap<CharSequence, Object> implements Node<Map<CharSequence, Object>> {
public StandardMapNode() {
}
public boolean has(String name) { public boolean has(String name) {
return containsKey(name); return containsKey(name);
} }

@ -271,7 +271,7 @@ public class StreamParser implements Parser {
private void expectChar(char expected) throws JsonException { private void expectChar(char expected) throws JsonException {
if (ch != expected) { if (ch != expected) {
throw new JsonException("expected char " + (char)expected + " but got " + (char)ch); throw new JsonException("expected char " + expected + " but got " + (char)ch);
} }
} }

@ -17,6 +17,9 @@ public class TinyJsonListener implements JsonResult {
private final ValueNode FALSE_NODE = new ValueNode(Boolean.FALSE); private final ValueNode FALSE_NODE = new ValueNode(Boolean.FALSE);
public TinyJsonListener() {
}
@Override @Override
public Node<?> getResult() { public Node<?> getResult() {
return node; return node;

@ -8,6 +8,9 @@ import java.util.function.Consumer;
public abstract class IndexedListBase<T> extends IndexedCollectionBase<T> implements IndexedList<T> { public abstract class IndexedListBase<T> extends IndexedCollectionBase<T> implements IndexedList<T> {
public IndexedListBase() {
}
@Override @Override
public boolean addAll(int index, Collection<? extends T> collection) { public boolean addAll(int index, Collection<? extends T> collection) {
boolean added = false; boolean added = false;

@ -6,8 +6,12 @@ import java.util.Objects;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
public abstract class IndexedMapBase<K, V> implements IndexedMap<K, V> { public abstract class IndexedMapBase<K, V> implements IndexedMap<K, V> {
private static final Object SENTINEL = new Object(); private static final Object SENTINEL = new Object();
public IndexedMapBase() {
}
@Override @Override
public V getOrDefault(Object key, V defaultValue) { public V getOrDefault(Object key, V defaultValue) {
int index = getIndex(key); int index = getIndex(key);

@ -5,6 +5,9 @@ import java.util.Set;
public abstract class IndexedSetBase<T> extends IndexedCollectionBase<T> implements IndexedSet<T> { public abstract class IndexedSetBase<T> extends IndexedCollectionBase<T> implements IndexedSet<T> {
public IndexedSetBase() {
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) { if (this == o) {

@ -2,6 +2,9 @@ package org.xbib.datastructures.tiny;
public abstract class Preconditions { public abstract class Preconditions {
public Preconditions() {
}
public static void checkArgument(boolean expression, String errorMessage) { public static void checkArgument(boolean expression, String errorMessage) {
if (!expression) { if (!expression) {
throw new IllegalArgumentException(errorMessage); throw new IllegalArgumentException(errorMessage);

@ -5,6 +5,9 @@ import java.util.Objects;
public abstract class TinySet<T> extends IndexedSetBase<T> { public abstract class TinySet<T> extends IndexedSetBase<T> {
public TinySet() {
}
public static int tableSize(int length) { public static int tableSize(int length) {
return Integer.highestOneBit(length * 2 - 1) * 2; return Integer.highestOneBit(length * 2 - 1) * 2;
} }

@ -1,5 +1,5 @@
group = org.xbib group = org.xbib
name = datastructures name = datastructures
version = 1.0.1 version = 2.0.0
org.gradle.warning.mode = ALL org.gradle.warning.mode = ALL

@ -6,13 +6,13 @@ java {
} }
compileJava { compileJava {
sourceCompatibility = JavaVersion.VERSION_11 sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_17
} }
compileTestJava { compileTestJava {
sourceCompatibility = JavaVersion.VERSION_11 sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_17
} }
jar { jar {
@ -38,10 +38,11 @@ artifacts {
} }
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
// commented out mostly because of jmh generated code options.compilerArgs.add('-Xlint:all')
options.compilerArgs << '-Xlint:all' options.encoding = 'UTF-8'
} }
javadoc { tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet') options.addStringOption('Xdoclint:none', '-quiet')
options.encoding = 'UTF-8'
} }

Loading…
Cancel
Save