Skip to content

Commit fe831dd

Browse files
authored
Clean up CF definitions (#101)
* initial refactoring * some more cleanups * cleanups
1 parent bcaf380 commit fe831dd

File tree

34 files changed

+188
-115
lines changed

34 files changed

+188
-115
lines changed

api/src/main/java/net/automatalib/automaton/visualization/ProceduralVisualizationHelper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ protected Collection<Pair<I, S>> initialNodes() {
6565

6666
for (Entry<I, UniversalDeterministicAutomaton<S, I, ?, ?, ?>> e : subModels.entrySet()) {
6767
final S init = e.getValue().getInitialState();
68-
assert init != null;
69-
initialNodes.add(Pair.of(e.getKey(), init));
68+
if (init != null) {
69+
initialNodes.add(Pair.of(e.getKey(), init));
70+
}
7071
}
7172

7273
return initialNodes;

build-config/src/main/resources/automatalib-spotbugs-exclusions.xml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,21 @@ limitations under the License.
3535
</Match>
3636
<Match>
3737
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"/>
38-
<And>
39-
<!-- Fine according to JavaDoc -->
40-
<Class name="net.automatalib.common.smartcollection.AbstractLinkedList"/>
41-
<Or>
42-
<Method name="popBack" returns="java.lang.Object"/>
43-
<Method name="popFront" returns="java.lang.Object"/>
44-
</Or>
45-
</And>
38+
<Or>
39+
<And>
40+
<!-- Fine according to data-flow -->
41+
<Class name="net.automatalib.util.automaton.ads.LeeYannakakis"/>
42+
<Method name="computeValidities"/>
43+
</And>
44+
<And>
45+
<!-- Fine according to JavaDoc -->
46+
<Class name="net.automatalib.common.smartcollection.AbstractLinkedList"/>
47+
<Or>
48+
<Method name="popBack" returns="java.lang.Object"/>
49+
<Method name="popFront" returns="java.lang.Object"/>
50+
</Or>
51+
</And>
52+
</Or>
4653
</Match>
4754
<Match>
4855
<!-- Passing references is mostly fine for performance reasons. Since we do not deal with security-related code,

build-parent/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ limitations under the License.
240240
<goal>compile</goal>
241241
</goals>
242242
<configuration>
243-
<failOnWarning>true</failOnWarning>
244243
<fork>true</fork>
245244
<outputDirectory>${project.build.directory}/checkerframework</outputDirectory>
246245
<annotationProcessorPaths combine.children="append">
@@ -273,7 +272,6 @@ limitations under the License.
273272
</arg>
274273
<arg>-AskipUses=^java.(awt.*|util.(Arrays|Map|ArrayDeque)|io.StreamTokenizer)|^javax.swing.*</arg>
275274
<arg>-AsuppressWarnings=uninitialized</arg>
276-
<arg>-AassumeAssertionsAreEnabled</arg>
277275
<arg>-Astubs=collection-object-parameters-may-be-null.astub</arg>
278276
</compilerArgs>
279277
</configuration>
@@ -285,7 +283,6 @@ limitations under the License.
285283
<goal>testCompile</goal>
286284
</goals>
287285
<configuration>
288-
<failOnWarning>true</failOnWarning>
289286
<fork>true</fork>
290287
<outputDirectory>${project.build.directory}/checkerframework</outputDirectory>
291288
<annotationProcessorPaths combine.children="append">
@@ -311,7 +308,6 @@ limitations under the License.
311308
<arg>-AonlyDefs=^net\.automatalib</arg>
312309
<arg>-AskipUses=.*</arg>
313310
<arg>-AsuppressWarnings=uninitialized</arg>
314-
<arg>-AassumeAssertionsAreEnabled</arg>
315311
<arg>-Astubs=collection-object-parameters-may-be-null.astub</arg>
316312
</compilerArgs>
317313
</configuration>

commons/smartcollections/src/main/java/net/automatalib/common/smartcollection/ReflexiveMapView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class ReflexiveMapView<T> extends AbstractMap<T, T> {
3636

3737
private final Set<@KeyFor("this") T> domain;
3838

39+
@SuppressWarnings("type") // the provided items become keys for this map view
3940
public ReflexiveMapView(Set<T> domain) {
4041
this.domain = Collections.unmodifiableSet(domain);
4142
}
@@ -68,6 +69,7 @@ public boolean containsKey(@Nullable Object key) {
6869
}
6970

7071
@Override
72+
@SuppressWarnings("return") // it is okay that values are also keys for this map
7173
public Set<T> values() {
7274
return this.domain;
7375
}

core/src/main/java/net/automatalib/automaton/mmlt/impl/DefaultMMLTSemantics.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import net.automatalib.symbol.time.TimedInput;
3333
import net.automatalib.symbol.time.TimedOutput;
3434
import net.automatalib.symbol.time.TimeoutSymbol;
35+
import org.checkerframework.checker.nullness.qual.NonNull;
3536
import org.checkerframework.checker.nullness.qual.Nullable;
3637
import org.slf4j.Logger;
3738
import org.slf4j.LoggerFactory;
@@ -132,8 +133,9 @@ public MealyTransition<State<S, O>, TimedOutput<O>> getTransition(State<S, O> so
132133
}
133134
}
134135

135-
assert lastOutput != null;
136-
return new MealyTransition<>(currentConfig, new TimedOutput<>(lastOutput));
136+
@SuppressWarnings("nullness") // since remainingTime must be > 0, the while loop iterates at least once
137+
final @NonNull O output = lastOutput;
138+
return new MealyTransition<>(currentConfig, new TimedOutput<>(output));
137139
} else {
138140
throw new IllegalArgumentException("Unknown input symbol type");
139141
}

core/src/main/java/net/automatalib/automaton/procedural/impl/StackSPA.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public StackSPA(ProceduralInputAlphabet<I> alphabet,
5050
}
5151

5252
@Override
53-
public StackState<S, I, DFA<S, I>> getTransition(StackState<S, I, DFA<S, I>> state, I input) {
53+
public @Nullable StackState<S, I, DFA<S, I>> getTransition(StackState<S, I, DFA<S, I>> state, I input) {
5454
if (state.isTerm()) {
5555
return null;
5656
} else if (alphabet.isInternalSymbol(input)) {

core/src/main/java/net/automatalib/automaton/procedural/impl/StackState.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package net.automatalib.automaton.procedural.impl;
1717

18-
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
1918
import org.checkerframework.checker.nullness.qual.Nullable;
2019

2120
/**
@@ -54,21 +53,25 @@ StackState<S, I, P> push(P newProcedure, S newState) {
5453
return new StackState<>(this, newProcedure, newState);
5554
}
5655

56+
@SuppressWarnings("return") // since this method is package-private, we are happy to only assert nullability
5757
StackState<S, I, P> pop() {
5858
assert !isStatic() : "This method should never be called on static states";
5959
return prev;
6060
}
6161

62+
@SuppressWarnings("type") // since this method is package-private, we are happy to only assert nullability
6263
StackState<S, I, P> updateState(S state) {
6364
assert !isStatic() : "This method should never be called on static states";
6465
return new StackState<>(prev, procedure, state);
6566
}
6667

68+
@SuppressWarnings("return") // since this method is package-private, we are happy to only assert nullability
6769
P getProcedure() {
6870
assert !isStatic() : "This method should never be called on static states";
6971
return procedure;
7072
}
7173

74+
@SuppressWarnings("return") // since this method is package-private, we are happy to only assert nullability
7275
S getCurrentState() {
7376
assert !isStatic() : "This method should never be called on static states";
7477
return procedureState;
@@ -92,9 +95,6 @@ boolean isTerm() {
9295
return this == TERM;
9396
}
9497

95-
// contract is satisfied by definition of constructors
96-
@SuppressWarnings("contracts.conditional.postcondition")
97-
@EnsuresNonNullIf(expression = {"this.prev", "this.procedure", "this.procedureState"}, result = false)
9898
private boolean isStatic() {
9999
return isInit() || isTerm();
100100
}

examples/src/main/java/net/automatalib/example/graph/DFSExample.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import net.automatalib.visualization.Visualization;
3131
import net.automatalib.visualization.VisualizationHelper;
3232
import net.automatalib.visualization.VisualizationHelper.EdgeStyles;
33+
import org.checkerframework.checker.nullness.qual.NonNull;
3334

3435
/**
3536
* A small example of a {@link GraphTraversal graph traversal} that uses a custom {@link GraphTraversalVisitor} to
@@ -168,16 +169,16 @@ static class DFSResultDOTHelper<N, E> implements VisualizationHelper<N, E> {
168169
@Override
169170
public boolean getNodeProperties(N node, Map<String, String> properties) {
170171
String lbl = properties.get(NodeAttrs.LABEL);
171-
DFSData record = records.get(node);
172-
assert record != null;
172+
@SuppressWarnings("nullness") // we have traversed all nodes before
173+
@NonNull DFSData record = records.get(node);
173174
properties.put(NodeAttrs.LABEL, lbl + " [#" + record.dfsNumber + "]");
174175
return true;
175176
}
176177

177178
@Override
178179
public boolean getEdgeProperties(N src, E edge, N tgt, Map<String, String> properties) {
179-
EdgeType et = edgeTypes.get(edge);
180-
assert et != null;
180+
@SuppressWarnings("nullness") // we have traversed all nodes before
181+
@NonNull EdgeType et = edgeTypes.get(edge);
181182
properties.put(EdgeAttrs.STYLE, et.getStyle());
182183
properties.remove(EdgeAttrs.LABEL);
183184
return true;

incremental/src/main/java/net/automatalib/incremental/dfa/dag/IncrementalDFADAGBuilder.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import net.automatalib.incremental.ConflictException;
2424
import net.automatalib.incremental.dfa.Acceptance;
2525
import net.automatalib.word.Word;
26+
import org.checkerframework.checker.nullness.qual.NonNull;
2627
import org.checkerframework.checker.nullness.qual.Nullable;
2728

2829
/**
@@ -74,7 +75,6 @@ public Acceptance lookup(Word<? extends I> word) {
7475
*/
7576
@Override
7677
public void insert(Word<? extends I> word, boolean accepting) {
77-
int len = word.length();
7878
Acceptance acc = Acceptance.fromBoolean(accepting);
7979

8080
State curr = init;
@@ -99,6 +99,7 @@ public void insert(Word<? extends I> word, boolean accepting) {
9999
curr = succ;
100100
}
101101

102+
int len = word.length();
102103
int prefixLen = path.size();
103104

104105
State last = curr;
@@ -139,8 +140,9 @@ public void insert(Word<? extends I> word, boolean accepting) {
139140
// confluence always requires cloning, to separate this path from other paths
140141
last = hiddenClone(last);
141142
if (conf == null) {
142-
Transition peek = path.peek();
143-
assert peek != null;
143+
// the root node is never confluent so in this context, the path always contains at least one node
144+
@SuppressWarnings("nullness")
145+
@NonNull Transition peek = path.peek();
144146
State prev = peek.state;
145147
if (prev == init) {
146148
updateInitSignature(peek.transIdx, last);

incremental/src/main/java/net/automatalib/incremental/dfa/dag/IncrementalPCDFADAGBuilder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import net.automatalib.incremental.ConflictException;
2424
import net.automatalib.incremental.dfa.Acceptance;
2525
import net.automatalib.word.Word;
26+
import org.checkerframework.checker.nullness.qual.NonNull;
2627

2728
/**
2829
* The prefix-closed version of {@link IncrementalDFADAGBuilder}. Contrary to the regular lookup semantics, where an
@@ -145,8 +146,9 @@ public void insert(Word<? extends I> word, boolean accepting) {
145146
}
146147
last = hiddenClone(last);
147148
if (conf == null) {
148-
Transition peek = path.peek();
149-
assert peek != null;
149+
// the root node is never confluent so in this context, the path always contains at least one node
150+
@SuppressWarnings("nullness")
151+
@NonNull Transition peek = path.peek();
150152
State prev = peek.state;
151153
if (prev == init) {
152154
updateInitSignature(peek.transIdx, last);

0 commit comments

Comments
 (0)