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;
import org.xbib.datastructures.common.StrictArraySet;
import java.util.AbstractMap;
import java.util.Collection;
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) {
for (int i = 0; i < keys.length; i++ ) {
if (keys[i].equals(key)) {
return (V) values[i];
return values[i];
}
}
return null;
@ -113,10 +112,10 @@ public class StrictArrayMap<K, V> extends AbstractMap<K, V> implements Map<K, V>
return new StrictArraySet<>(values);
}
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
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++) {
entries[i] = new EntryHolder<>(keys[i], values[i]);
}

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

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

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

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

@ -156,7 +156,7 @@ public class FastDoubleParser {
if (neg_exp) {
exp_number = -exp_number;
}
exponent += exp_number;
exponent = exponent + (int)exp_number;
}
index = skipWhitespace(str, index, endIndex);
if (index < endIndex
@ -164,7 +164,7 @@ public class FastDoubleParser {
throw newNumberFormatException(str);
}
final boolean isDigitsTruncated;
int skipCountInTruncatedDigits = 0;//counts +1 if we skipped over the decimal point
int skipCountInTruncatedDigits = 0;
if (digitCount > 19) {
digits = 0;
for (index = indexOfFirstDigit; index < indexAfterDigits; index++) {
@ -231,10 +231,7 @@ public class FastDoubleParser {
if (index >= endIndex) {
throw newNumberFormatException(str);
}
// Parse digits
// ------------
long digits = 0;// digits is treated as an unsigned long
long digits = 0;
int exponent = 0;
final int indexOfFirstDigit = index;
int virtualIndexOfPoint = -1;
@ -242,10 +239,9 @@ public class FastDoubleParser {
char ch = 0;
for (; index < endIndex; 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];
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) {
if (virtualIndexOfPoint != -1) {
throw newNumberFormatException(str);
@ -263,9 +259,6 @@ public class FastDoubleParser {
digitCount = indexAfterDigits - indexOfFirstDigit - 1;
exponent = Math.min(virtualIndexOfPoint - index + 1, MINIMAL_EIGHT_DIGIT_INTEGER) * 4;
}
// Parse exponent number
// ---------------------
long exp_number = 0;
final boolean hasExponent = (ch == 'p') || (ch == 'P');
if (hasExponent) {
@ -278,7 +271,6 @@ public class FastDoubleParser {
throw newNumberFormatException(str);
}
do {
// Guard against overflow of exp_number
if (exp_number < MINIMAL_EIGHT_DIGIT_INTEGER) {
exp_number = 10 * exp_number + ch - '0';
}
@ -287,27 +279,20 @@ public class FastDoubleParser {
if (neg_exp) {
exp_number = -exp_number;
}
exponent += exp_number;
exponent = exponent + (int)exp_number;
}
// Skip trailing whitespace
// ------------------------
index = skipWhitespace(str, index, endIndex);
if (index < endIndex
|| digitCount == 0 && str.charAt(virtualIndexOfPoint) != '.'
|| !hasExponent) {
throw newNumberFormatException(str);
}
// Re-parse digits in case of a potential overflow
// -----------------------------------------------
final boolean isDigitsTruncated;
int skipCountInTruncatedDigits = 0;//counts +1 if we skipped over the decimal point
int skipCountInTruncatedDigits = 0;
if (digitCount > 16) {
digits = 0;
for (index = indexOfFirstDigit; index < indexAfterDigits; 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];
if (hexValue >= 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 ListNode() {
}
public boolean has(int i) {
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 MapNode() {
}
public boolean has(String name) {
return containsKey(name);
}

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

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

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

@ -271,7 +271,7 @@ public class StreamParser implements Parser {
private void expectChar(char expected) throws JsonException {
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);
public TinyJsonListener() {
}
@Override
public Node<?> getResult() {
return node;

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

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

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

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

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

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

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

Loading…
Cancel
Save