Skip to content

Commit e80554b

Browse files
committed
fix validation errors & cleanup
* false-positive of the SpotBugs Plugin on Java 11 * better nullability specification + tests
1 parent c7d108a commit e80554b

4 files changed

Lines changed: 82 additions & 24 deletions

File tree

build-tools/build-config/src/main/resources/learnlib-spotbugs-exclusions.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,11 @@ limitations under the License.
4242
<Class name="de.learnlib.datastructure.observationtable.writer.ObservationTableWriter"/>
4343
</Or>
4444
</Match>
45+
<Match>
46+
<!-- False-positive on Java 11. See https://github.com/spotbugs/spotbugs/issues/259 -->
47+
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"/>
48+
<Or>
49+
<Class name="de.learnlib.examples.dfa.DFABenchmarks"/>
50+
</Or>
51+
</Match>
4552
</FindBugsFilter>

test-support/learning-examples/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@ limitations under the License.
6565
<artifactId>checker-qual</artifactId>
6666
</dependency>
6767

68-
<!-- test -->
6968
<dependency>
7069
<groupId>org.slf4j</groupId>
7170
<artifactId>slf4j-api</artifactId>
7271
</dependency>
72+
73+
<!-- test -->
74+
<dependency>
75+
<groupId>org.testng</groupId>
76+
<artifactId>testng</artifactId>
77+
</dependency>
7378
</dependencies>
7479
</project>

test-support/learning-examples/src/main/java/de/learnlib/examples/dfa/DFABenchmarks.java

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.IOException;
1919
import java.io.InputStream;
20+
import java.util.Objects;
2021

2122
import de.learnlib.examples.DefaultLearningExample.DefaultDFALearningExample;
2223
import de.learnlib.examples.LearningExample.DFALearningExample;
@@ -34,38 +35,41 @@ private DFABenchmarks() {
3435
// prevent instantiation
3536
}
3637

37-
public static @Nullable DFALearningExample<Integer> loadPots2() {
38-
return loadLearnLibV2Benchmark("pots2");
39-
}
40-
4138
public static @Nullable DFALearningExample<Integer> loadLearnLibV2Benchmark(String name) {
42-
String resourceName = "/automata/learnlibv2/" + name + ".dfa.gz";
43-
if (DFABenchmarks.class.getResource(resourceName) == null) {
44-
return null;
45-
}
39+
final String resourceName = "/automata/learnlibv2/" + name + ".dfa.gz";
40+
final InputStream resourceStream = DFABenchmarks.class.getResourceAsStream(resourceName);
4641

47-
try (InputStream is = DFABenchmarks.class.getResourceAsStream(resourceName)) {
48-
if (is == null) {
49-
LOGGER.warn("Couldn't load resource '{}'", resourceName);
50-
return null;
42+
if (resourceStream == null) {
43+
LOGGER.info("Couldn't find resource '{}'", resourceName);
44+
} else {
45+
try (InputStream is = resourceStream) {
46+
CompactDFA<Integer> dfa = LearnLibV2Serialization.getInstance().readGenericDFA(is);
47+
return new DefaultDFALearningExample<>(dfa);
48+
} catch (IOException ex) {
49+
LOGGER.error("Could not load benchmark", ex);
5150
}
52-
CompactDFA<Integer> dfa = LearnLibV2Serialization.getInstance().readGenericDFA(is);
53-
return new DefaultDFALearningExample<>(dfa);
54-
} catch (IOException ex) {
55-
LOGGER.error("Could not load benchmark", ex);
56-
return null;
5751
}
52+
53+
return null;
54+
}
55+
56+
public static DFALearningExample<Integer> loadPots2() {
57+
return Objects.requireNonNull(loadLearnLibV2Benchmark("pots2"),
58+
"Couldn't find 'pots2'. Are the correct JARs loaded?");
5859
}
5960

60-
public static @Nullable DFALearningExample<Integer> loadPots3() {
61-
return loadLearnLibV2Benchmark("pots3");
61+
public static DFALearningExample<Integer> loadPots3() {
62+
return Objects.requireNonNull(loadLearnLibV2Benchmark("pots3"),
63+
"Couldn't find 'pots3'. Are the correct JARs loaded?");
6264
}
6365

64-
public static @Nullable DFALearningExample<Integer> loadPeterson2() {
65-
return loadLearnLibV2Benchmark("peterson2");
66+
public static DFALearningExample<Integer> loadPeterson2() {
67+
return Objects.requireNonNull(loadLearnLibV2Benchmark("peterson2"),
68+
"Couldn't find 'peterson2'. Are the correct JARs loaded?");
6669
}
6770

68-
public static @Nullable DFALearningExample<Integer> loadPeterson3() {
69-
return loadLearnLibV2Benchmark("peterson3");
71+
public static DFALearningExample<Integer> loadPeterson3() {
72+
return Objects.requireNonNull(loadLearnLibV2Benchmark("peterson3"),
73+
"Couldn't find 'peterson3'. Are the correct JARs loaded?");
7074
}
7175
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* Copyright (C) 2013-2019 TU Dortmund
2+
* This file is part of LearnLib, http://www.learnlib.de/.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package de.learnlib.examples.dfa;
17+
18+
import org.testng.Assert;
19+
import org.testng.annotations.Test;
20+
21+
public class DFAExamplesTest {
22+
23+
@Test
24+
public void testPots2() {
25+
Assert.assertNotNull(DFABenchmarks.loadPots2());
26+
}
27+
28+
@Test
29+
public void testPots3() {
30+
Assert.assertNotNull(DFABenchmarks.loadPots3());
31+
}
32+
33+
@Test
34+
public void testPeterson2() {
35+
Assert.assertNotNull(DFABenchmarks.loadPeterson2());
36+
}
37+
38+
@Test
39+
public void testPeterson3() {
40+
Assert.assertNotNull(DFABenchmarks.loadPeterson3());
41+
}
42+
}

0 commit comments

Comments
 (0)