Skip to content

Commit

Permalink
Merge pull request #32199 from vespa-engine/balder/avoid-java21-this-…
Browse files Browse the repository at this point in the history
…escape-warning-9

Avoid this escape.
  • Loading branch information
baldersheim authored Aug 21, 2024
2 parents 50ec521 + a2ce6ef commit 79e03d2
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import java.util.logging.Logger;

public class AsyncOperationImpl<T> implements AsyncOperation<T> {
public final class AsyncOperationImpl<T> implements AsyncOperation<T> {

private static final Logger log = Logger.getLogger(AsyncOperationImpl.class.getName());
private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public class FileSource implements ConfigSource {
private final File file;

public FileSource(File file) {
this.file = file;
validateFile();
this.file = validateFile(file);
}

public long getLastModified() {
Expand All @@ -29,8 +28,12 @@ public List<String> getContent() throws IOException {
return Files.readAllLines(file.toPath());
}

public void validateFile() {
private static File validateFile(File file) {
if ( ! file.isFile()) throw new IllegalArgumentException("Not a file: " + file);
return file;
}
public void validateFile() {
validateFile(file);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public JRTConnectionPool(ConfigSourceSet sourceSet, Supervisor supervisor) {
addSources(sourceSet);
}

public void addSources(ConfigSourceSet sourceSet) {
private void addSources(ConfigSourceSet sourceSet) {
this.sourceSet = sourceSet;
synchronized (connections) {
for (String address : sourceSet.getSources()) {
Expand Down Expand Up @@ -91,15 +91,15 @@ synchronized JRTConnection switchConnection() {
return currentConnection = newConnection;
}

public synchronized JRTConnection initialize() {
private synchronized JRTConnection initialize() {
return pickNewConnectionRandomly(getSources());
}

protected JRTConnection pickNewConnectionRandomly(List<JRTConnection> sources) {
final protected JRTConnection pickNewConnectionRandomly(List<JRTConnection> sources) {
return sources.get(ThreadLocalRandom.current().nextInt(0, sources.size()));
}

public List<JRTConnection> getSources() {
final public List<JRTConnection> getSources() {
List<JRTConnection> ret;
synchronized (connections) {
ret = new ArrayList<>(connections.values());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
* @author Ulf Lilleengen
*/
public class JRTClientConfigRequestV3 implements JRTClientConfigRequest {
public final class JRTClientConfigRequestV3 implements JRTClientConfigRequest {

protected static final Logger log = Logger.getLogger(JRTClientConfigRequestV3.class.getName());
protected final SlimeRequestData requestData;
Expand Down
2 changes: 1 addition & 1 deletion jrt/src/com/yahoo/jrt/Transport.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* some additional helper threads. A single Transport object can back
* multiple {@link Supervisor} objects.
*/
public class Transport {
public final class Transport {

private static final Logger log = Logger.getLogger(Transport.class.getName());

Expand Down
46 changes: 19 additions & 27 deletions jrt/tests/com/yahoo/jrt/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,33 +147,25 @@ public static boolean equals(Value a, Value b) {
if (a.type() != b.type()) {
return false;
}
switch (a.type()) {
case Value.INT8: return (a.asInt8() == b.asInt8());
case Value.INT8_ARRAY: return Arrays.equals(a.asInt8Array(),
b.asInt8Array());
case Value.INT16: return (a.asInt16() == b.asInt16());
case Value.INT16_ARRAY: return Arrays.equals(a.asInt16Array(),
b.asInt16Array());
case Value.INT32: return (a.asInt32() == b.asInt32());
case Value.INT32_ARRAY: return Arrays.equals(a.asInt32Array(),
b.asInt32Array());
case Value.INT64: return (a.asInt64() == b.asInt64());
case Value.INT64_ARRAY: return Arrays.equals(a.asInt64Array(),
b.asInt64Array());
case Value.FLOAT: return (a.asFloat() == b.asFloat());
case Value.FLOAT_ARRAY: return Arrays.equals(a.asFloatArray(),
b.asFloatArray());
case Value.DOUBLE: return (a.asDouble() == b.asDouble());
case Value.DOUBLE_ARRAY: return Arrays.equals(a.asDoubleArray(),
b.asDoubleArray());
case Value.DATA: return Arrays.equals(a.asData(), b.asData());
case Value.DATA_ARRAY: return equals(a.asDataArray(),
b.asDataArray());
case Value.STRING: return a.asString().equals(b.asString());
case Value.STRING_ARRAY: return Arrays.equals(a.asStringArray(),
b.asStringArray());
default: return false;
}
return switch (a.type()) {
case Value.INT8 -> (a.asInt8() == b.asInt8());
case Value.INT8_ARRAY -> Arrays.equals(a.asInt8Array(), b.asInt8Array());
case Value.INT16 -> (a.asInt16() == b.asInt16());
case Value.INT16_ARRAY -> Arrays.equals(a.asInt16Array(), b.asInt16Array());
case Value.INT32 -> (a.asInt32() == b.asInt32());
case Value.INT32_ARRAY -> Arrays.equals(a.asInt32Array(), b.asInt32Array());
case Value.INT64 -> (a.asInt64() == b.asInt64());
case Value.INT64_ARRAY -> Arrays.equals(a.asInt64Array(), b.asInt64Array());
case Value.FLOAT -> (a.asFloat() == b.asFloat());
case Value.FLOAT_ARRAY -> Arrays.equals(a.asFloatArray(), b.asFloatArray());
case Value.DOUBLE -> (a.asDouble() == b.asDouble());
case Value.DOUBLE_ARRAY -> Arrays.equals(a.asDoubleArray(), b.asDoubleArray());
case Value.DATA -> Arrays.equals(a.asData(), b.asData());
case Value.DATA_ARRAY -> equals(a.asDataArray(), b.asDataArray());
case Value.STRING -> a.asString().equals(b.asString());
case Value.STRING_ARRAY -> Arrays.equals(a.asStringArray(), b.asStringArray());
default -> false;
};
}

public static boolean equals(Values a, Values b) {
Expand Down
3 changes: 2 additions & 1 deletion linguistics/abi-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@
"superClass" : "java.util.AbstractList",
"interfaces" : [ ],
"attributes" : [
"public"
"public",
"final"
],
"methods" : [
"public void <init>()",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @author steinar
*/
public class StemList extends AbstractList<String> {
public final class StemList extends AbstractList<String> {

private final List<String> stems;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* @author MariusArhaug
*/
public class DefaultSignificanceModelRegistry implements SignificanceModelRegistry {
public final class DefaultSignificanceModelRegistry implements SignificanceModelRegistry {

private static final Logger log = Logger.getLogger(DefaultSignificanceModelRegistry.class.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.AbstractSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
Expand All @@ -22,13 +23,13 @@
* by char[] keys without the necessity of converting
* to a String first.
*/
public class CharArrayMap<V> extends AbstractMap<Object,V> {
class CharArrayMap<V> extends AbstractMap<Object,V> {

private static final CharArrayMap<?> EMPTY_MAP = new EmptyCharArrayMap<>();

private final static int INIT_SIZE = 8;
private final CharacterUtils charUtils;
private boolean ignoreCase;
private final boolean ignoreCase;
private int count;
char[][] keys; // package private because used in CharArraySet's non Set-conform CharArraySetIterator
V[] values; // package private because used in CharArraySet's non Set-conform CharArraySetIterator
Expand Down Expand Up @@ -97,9 +98,8 @@ public boolean containsKey(CharSequence cs) {

@Override
public boolean containsKey(Object o) {
if (o instanceof char[]) {
final char[] text = (char[])o;
return containsKey(text, 0, text.length);
if (o instanceof char[] text) {
return containsKey(text, 0, text.length);
}
return containsKey(o.toString());
}
Expand All @@ -117,9 +117,8 @@ public V get(CharSequence cs) {

@Override
public V get(Object o) {
if (o instanceof char[]) {
final char[] text = (char[])o;
return get(text, 0, text.length);
if (o instanceof char[] text) {
return get(text, 0, text.length);
}
return get(o.toString());
}
Expand Down Expand Up @@ -484,7 +483,7 @@ public boolean contains(Object o) {
final Object key = e.getKey();
final Object val = e.getValue();
final Object v = get(key);
return v == null ? val == null : v.equals(val);
return Objects.equals(v, val);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* buffer. The same behavior have the {@code contains()} methods.
* The {@link #iterator()} returns an {@code Iterator<char[]>}.
*/
public class CharArraySet extends AbstractSet<Object> {
class CharArraySet extends AbstractSet<Object> {

public static final CharArraySet EMPTY_SET = new CharArraySet(CharArrayMap.<Object>emptyMap());
private static final Object PLACEHOLDER = new Object();
Expand Down Expand Up @@ -151,17 +151,16 @@ public static CharArraySet unmodifiableSet(CharArraySet set) {
public static CharArraySet copy(final Set<?> set) {
if(set == EMPTY_SET)
return EMPTY_SET;
if(set instanceof CharArraySet) {
final CharArraySet source = (CharArraySet) set;
return new CharArraySet(CharArrayMap.copy(source.map));
if(set instanceof CharArraySet source) {
return new CharArraySet(CharArrayMap.copy(source.map));
}
return new CharArraySet(set, false);
}

/**
* Returns an {@link Iterator} for {@code char[]} instances in this set.
*/
@Override @SuppressWarnings("unchecked")
@Override
public Iterator<Object> iterator() {
// use the AbstractSet#keySet()'s iterator (to not produce endless recursion)
return map.originalKeySet().iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author Bjorn Borud
*/
public class ArchiverHandler extends AbstractLogHandler {
public final class ArchiverHandler extends AbstractLogHandler {
private static final Logger log = Logger.getLogger(ArchiverHandler.class.getName());

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@

import com.yahoo.compress.ZstdOutputStream;
import com.yahoo.io.NativeIO;
import com.yahoo.log.LogFileDb;
import com.yahoo.protect.Process;
import com.yahoo.yolean.Exceptions;

import java.io.BufferedOutputStream;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.OutputStream;
Expand All @@ -36,7 +32,7 @@
*
* @author Arne Juul
*/
public class FilesArchived {
public final class FilesArchived {
private static final Logger log = Logger.getLogger(FilesArchived.class.getName());

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @author Bjorn Borud
*/
public class LogWriter {
public final class LogWriter {
private static final Logger log = Logger.getLogger(LogWriter.class.getName());

private long bytesWritten = 0;
Expand Down

0 comments on commit 79e03d2

Please sign in to comment.