Skip to content

Commit

Permalink
Fixes based on Eclipse null analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
agentgt committed Dec 10, 2024
1 parent f6f2f37 commit 92e7fbd
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion etc/eea/java/util/Map$Entry.eea
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class java/util/Map$Entry
comparingByKey
<K::Ljava/lang/Comparable<-TK;>;V:Ljava/lang/Object;>()Ljava/util/Comparator<Ljava/util/Map$Entry<TK;TV;>;>;
<K::Ljava/lang/Comparable<-TK;>;V:Ljava/lang/Object;>()L1java/util/Comparator<Ljava/util/Map$Entry<TK;TV;>;>;
<K::Ljava/lang/Comparable<-TK;>;V:Ljava/lang/Object;>()L1java/util/Comparator<L1java/util/Map$Entry<TK;TV;>;>;
comparingByKey
<K:Ljava/lang/Object;V:Ljava/lang/Object;>(Ljava/util/Comparator<-TK;>;)Ljava/util/Comparator<Ljava/util/Map$Entry<TK;TV;>;>;
<K:Ljava/lang/Object;V:Ljava/lang/Object;>(L1java/util/Comparator<-TK;>;)L1java/util/Comparator<Ljava/util/Map$Entry<TK;TV;>;>;
Expand Down
3 changes: 3 additions & 0 deletions etc/eea/java/util/function/Function.eea
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class java/util/function/Function
andThen
<V:Ljava/lang/Object;>(Ljava/util/function/Function<-TR;+TV;>;)Ljava/util/function/Function<TT;TV;>;
<V:Ljava/lang/Object;>(Ljava/util/function/Function<-TR;+TV;>;)L1java/util/function/Function<TT;TV;>;
identity
<T:Ljava/lang/Object;>()Ljava/util/function/Function<TT;TT;>;
<T:Ljava/lang/Object;>()L1java/util/function/Function<TT;TT;>;
3 changes: 3 additions & 0 deletions etc/eea/java/util/stream/Collectors.eea
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class java/util/stream/Collectors
collectingAndThen
<T:Ljava/lang/Object;A:Ljava/lang/Object;R:Ljava/lang/Object;RR:Ljava/lang/Object;>(Ljava/util/stream/Collector<TT;TA;TR;>;Ljava/util/function/Function<TR;TRR;>;)Ljava/util/stream/Collector<TT;TA;TRR;>;
<T:Ljava/lang/Object;A:Ljava/lang/Object;R:Ljava/lang/Object;RR:Ljava/lang/Object;>(Ljava/util/stream/Collector<TT;TA;TR;>;Ljava/util/function/Function<TR;TRR;>;)L1java/util/stream/Collector<TT;TA;TRR;>;
joining
()Ljava/util/stream/Collector<Ljava/lang/CharSequence;*Ljava/lang/String;>;
()L1java/util/stream/Collector<Ljava/lang/CharSequence;*L1java/lang/String;>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected KeyValues load(LoaderContext context, KeyValuesResource resource) thro
@Override
protected KeyValues load(LoaderContext context, KeyValuesResource resource) throws IOException {
var builder = KeyValues.builder(resource);
@SuppressWarnings("null") // TODO eclipse null analysis bug

BiConsumer<String, String> consumer = builder::add;

String path = normalizePath(resource.uri());
Expand Down Expand Up @@ -114,6 +114,7 @@ protected KeyValues load(LoaderContext context, KeyValuesResource resource) thro

static void propertiesFromCommandLine(Iterable<String> args, BiConsumer<String, String> consumer) {
for (String arg : args) {
@NonNull
String[] kv = arg.split("=", 2);
if (kv.length < 2)
continue;
Expand Down Expand Up @@ -197,12 +198,10 @@ static KeyValues profiles(String scheme, LoaderContext context, KeyValuesResourc
logger.info("Found profiles: " + profiles);
KeyValues.Builder builder = KeyValues.builder(resource);

@SuppressWarnings("null") // TODO eclipse null analysis bug
BiConsumer<String, String> consumer = builder::add;

int i = 0;
for (var p : profiles) {
@SuppressWarnings("null") // TODO eclipse bug
var value = uriString.replace("__PROFILE__", p);
var b = resource.toBuilder();
b.uri(URI.create(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.function.BiConsumer;
import java.util.stream.Stream;

import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

import io.jstach.ezkv.kvs.KeyValuesServiceProvider.KeyValuesFilter.Filter;
Expand Down Expand Up @@ -246,6 +247,7 @@ private void parseURI(KeyValuesResource.Builder builder, URI uri) throws KeyValu
e);
}
if (rk == null) {
filtered.add(kv);
continue;
}
hasParameter = true;
Expand Down Expand Up @@ -275,9 +277,6 @@ private void parseURI(KeyValuesResource.Builder builder, URI uri) throws KeyValu
var f = new Filter(filter, expression, "");
builder._addFilter(f);
}
case null -> {
filtered.add(kv);
}
}
}
if (hasParameter) {
Expand Down Expand Up @@ -402,6 +401,7 @@ private String externalResourceKey2Prefix(ResourceKey type, String alias, String
return null;
}
String rest = key.substring(prefix.length());
@NonNull
String[] names = rest.split(sep(), 2);
if (names.length == 0) {
throw new KeyValuesResourceParserException("Bad resource key. type: " + type + " keyvalue: " + kv);
Expand Down Expand Up @@ -465,7 +465,7 @@ private enum ResourceKey {

final List<String> keys;

private ResourceKey(String key, String... rest) {
private ResourceKey(String key, @NonNull String... rest) {
this(Stream.concat(Stream.of(key), Stream.of(rest)).toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ record SubstitutionCommand(@Nullable Address address, String pattern, String rep
boolean isGlobal) implements Command {
@Override
public @Nullable String execute(String key) {
var address = this.address;
if (address == null || address.matches(key)) {
return isGlobal ? key.replaceAll(pattern, replacement) : key.replaceFirst(pattern, replacement);
}
Expand All @@ -194,6 +195,7 @@ record SubstitutionCommand(@Nullable Address address, String pattern, String rep
record DeleteCommand(@Nullable Address address) implements Command {
@Override
public @Nullable String execute(String key) {
var address = this.address;
if (address == null || address.matches(key)) {
return null; // Indicate that the key should be deleted
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.jstach.ezkv.kvs;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Documented
@Retention(RetentionPolicy.CLASS)
@interface FakeNonNullByDefault {

DefaultLocation[] value() default { DefaultLocation.PARAMETER, DefaultLocation.RETURN_TYPE, DefaultLocation.FIELD,
DefaultLocation.TYPE_BOUND, DefaultLocation.TYPE_ARGUMENT };

enum DefaultLocation {

PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS

}

}
2 changes: 2 additions & 0 deletions ezkv-kvs/src/main/java/io/jstach/ezkv/kvs/KeyValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public Builder add(Entry<String, String> e) {
return add(e.getKey(), e.getValue());
}

@SuppressWarnings("null") // Eclipse null analysis has some inference issue here
private static final Comparator<Entry<String, String>> entryComparator = Map.Entry
.<String, String>comparingByKey()
.thenComparing(Entry::getValue);
Expand Down Expand Up @@ -504,6 +505,7 @@ static KeyValues interpolateKeyValues(final KeyValues keyValues, final Variables
return null;

}).add(resolved).add(variables).build();
@SuppressWarnings("null")
Interpolator sub = Interpolator.create((key) -> {
return combined.getValue(key);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.net.URI;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;

Expand All @@ -19,7 +20,8 @@ sealed interface KeyValuesSource permits NamedKeyValuesSource, KeyValue.Source {
static final Pattern RESOURCE_NAME_PATTERN = Pattern.compile(KeyValuesResource.RESOURCE_NAME_REGEX);

static String validateName(String identifier) {
if (identifier == null || !RESOURCE_NAME_PATTERN.matcher(identifier).matches()) {
Objects.requireNonNull(identifier);
if (!RESOURCE_NAME_PATTERN.matcher(identifier).matches()) {
throw new IllegalArgumentException(
"Invalid resource name: must contain only alphanumeric characters (no underscores) and not be null. input: "
+ identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ default KeyValuesLoader.Builder loader() {
var env = environment();
var defaultResource = env.defaultResource();
var variables = Variables.copyOf(b.variables.stream().map(vf -> vf.apply(env)).toList());
var resources = b.sources.isEmpty() ? List.of(defaultResource) : List.copyOf(b.sources);
List<NamedKeyValuesSource> resources = b.sources.isEmpty() ? List.of(defaultResource)
: List.copyOf(b.sources);
return DefaultKeyValuesSourceLoader.of(this, variables, resources);
};
return new KeyValuesLoader.Builder(loaderFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@
* @see io.jstach.ezkv.kvs.KeyValuesResource
*/
@org.jspecify.annotations.NullMarked
@io.jstach.ezkv.kvs.FakeNonNullByDefault
package io.jstach.ezkv.kvs;

0 comments on commit 92e7fbd

Please sign in to comment.