Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Nullness Checker configuration #3183

Merged
merged 48 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c2245e5
Basic Nullness Checker configuration
wmdietl Jun 26, 2023
d1bc0a4
[small] merging 2 string util classes
mattulbrich Jun 26, 2023
018e5fe
Run spotlessApply, add missing Deprecated annotation
wmdietl Jun 26, 2023
2cf9325
Add testComileOnly depencency
wmdietl Jun 26, 2023
763b442
making all classes in util nullness aware
mattulbrich Jun 26, 2023
08673f9
nullness-specifying the StringUtil class
mattulbrich Jun 26, 2023
de7cdae
nullness-specifying class Filenames
mattulbrich Jun 26, 2023
652efd5
nonnull: addressing Werner's review comments
mattulbrich Jun 26, 2023
f95c90b
nullness-specifying some more classes
mattulbrich Jun 26, 2023
28ee001
nullness-specifying some more classes
mattulbrich Jun 27, 2023
c880594
nullness-specifying some more classes
mattulbrich Jun 27, 2023
f489d15
nonnull: adding stub infrastructure
mattulbrich Jun 28, 2023
edc3db2
nullness: continued to specify ImmutableList
mattulbrich Jun 28, 2023
b5b6455
more nullness specifications.
mattulbrich Jun 28, 2023
c9b24c5
wip
mattulbrich Jun 28, 2023
6280b57
nullness checks for ArrayUtil, Beans
mattulbrich Jul 6, 2023
a1b4bd1
nullness and refactoring of class ImmutableSet
mattulbrich Jul 6, 2023
d6b769d
Merge remote-tracking branch 'origin/main' into use-eisop
wadoon Jul 20, 2023
6a62091
JSR305 to jspecify
wadoon Jul 20, 2023
69a19d5
some more annotations
wadoon Jul 21, 2023
17fa5b0
pushing further
wadoon Jul 24, 2023
b4d6dda
Fix type error in KeYCollections.concat
flo2702 Oct 25, 2023
e6bc178
Merge remote-tracking branch 'upstream/main' into use-eisop
flo2702 Oct 27, 2023
ba9dad1
fix compile error
wadoon Nov 3, 2023
9e4f501
spotless
wadoon Nov 3, 2023
266f753
Fix compile errors
flo2702 Nov 8, 2023
860c5e1
Add readme to key.util
flo2702 Nov 8, 2023
3f3c801
Remove unnecessary @NullMarked annotations in @NullMarked packages
flo2702 Nov 8, 2023
4b5e128
Merge remote-tracking branch 'upstream/main' into use-eisop
flo2702 Nov 8, 2023
4d01325
Fix typos in Readme
flo2702 Nov 8, 2023
b7df720
Merge branch 'main' into use-eisop
wadoon Nov 18, 2023
b279636
Merge remote-tracking branch 'upstream/main' into use-eisop
flo2702 Nov 22, 2023
87bb979
Spotless
flo2702 Nov 22, 2023
76a3bd0
Merge branch 'main' into use-eisop
wadoon Dec 29, 2023
5a22f22
Merge branch 'main' into use-eisop
wadoon Feb 11, 2024
46b6744
making the switch working correctly
wadoon Feb 11, 2024
70bb2aa
repair suppres warning
wadoon Feb 11, 2024
cf03cb0
Merge remote-tracking branch 'origin/main' into use-eisop
wadoon Apr 5, 2024
33833f5
Merge branch 'main' into use-eisop
wadoon Apr 23, 2024
e316019
Merge branch 'main' into use-eisop
wadoon Apr 23, 2024
3c818af
Fix merge issues
flo2702 Apr 26, 2024
536d9f8
jspecify was missing in the compile classpath of tests
wadoon Apr 27, 2024
3c6d422
#equals must allow null values
wadoon Apr 27, 2024
9f44bbf
Remove redundant nullness checks and fix test cases
flo2702 Apr 30, 2024
3edb840
Merge remote-tracking branch 'upstream/main' into use-eisop
flo2702 Apr 30, 2024
9870edc
Fix NoSuchElementException in JavaInfo
flo2702 Apr 30, 2024
9b978f9
Fix more NoSuchElementExceptions
flo2702 Apr 30, 2024
1344580
Fix formatting
flo2702 May 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ plugins {

// Code formatting
id "com.diffplug.spotless" version "6.16.0"

// EISOP Checker Framework
id "org.checkerframework" version "0.6.28"
}

// Configure this project for use inside IntelliJ:
Expand Down Expand Up @@ -62,6 +65,7 @@ subprojects {
apply plugin: "com.diffplug.spotless"
apply plugin: "checkstyle"
apply plugin: "pmd"
apply plugin: "org.checkerframework"

group = rootProject.group
version = rootProject.version
Expand All @@ -84,6 +88,11 @@ subprojects {
//compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.12.0'
implementation 'com.google.code.findbugs:jsr305:3.0.2'

compileOnly 'org.jspecify:jspecify:0.3.0'
compileOnly 'io.github.eisop:checker-qual:3.34.0-eisop1'
testCompileOnly 'io.github.eisop:checker-qual:3.34.0-eisop1'
checkerFramework 'io.github.eisop:checker:3.34.0-eisop1'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.3'
testCompileOnly 'junit:junit:4.13.2'
Expand Down Expand Up @@ -405,6 +414,17 @@ subprojects {
}
}

checkerFramework {
checkers = [
"org.checkerframework.checker.nullness.NullnessChecker",
]
extraJavacArgs = [
"-AonlyDefs=^org\\.key_project\\.util",
"-Xmaxerrs", "10000",
"-Werror",
"-Aversion",
]
}
}

task start {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*
* @author Arne Keller
*/
@SuppressWarnings("nullness")
public final class EqualsModProofIrrelevancyUtil {
private EqualsModProofIrrelevancyUtil() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @param <T> type to wrap
* @author Arne Keller
*/
@SuppressWarnings("nullness")
public class EqualsModProofIrrelevancyWrapper<T extends EqualsModProofIrrelevancy> {
/**
* The wrapped object.
Expand Down
1 change: 1 addition & 0 deletions key.util/src/main/java/org/key_project/util/ExtList.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Extends java.util.LinkedList in order to collect elements according to their type.
* Has facilities to get elements of a certain type ({@link #get(Class)}, {@link #collect(Class)}).
*/
@SuppressWarnings("nullness")
public class ExtList extends LinkedList<Object> {

private static final long serialVersionUID = 9182017368310263908L;
Expand Down
7 changes: 6 additions & 1 deletion key.util/src/main/java/org/key_project/util/Filenames.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import java.util.Arrays;
import java.util.List;

import org.jspecify.annotations.NullMarked;

/**
* @author Alexander Weigl
* @version 1 (29.03.19)
*/
@NullMarked
public class Filenames {
// =======================================================
// Methods operating on Strings
Expand Down Expand Up @@ -153,7 +156,9 @@ private static String[] removeDotDot(String[] a) {
if (!a[a.length - 1].equals("..")) {
newa[k++] = a[a.length - 1];
}
return Arrays.copyOf(newa, k);
// @ assert (\forall int i; 0 <= i < k; newa[i] != null);
// TODO: nullness. This cast cannot be checked, can it? But there is no error message
return (String[]) Arrays.copyOf(newa, k);
}

public static String toValidFileName(String s) {
Expand Down
1 change: 1 addition & 0 deletions key.util/src/main/java/org/key_project/util/LRUCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/**
* Simple realisation of an LRU cache.
*/
@SuppressWarnings("nullness")
public class LRUCache<K, V> extends LinkedHashMap<K, V> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @author Alexander Weigl
* @version 1 (06.12.18)
*/
@SuppressWarnings("nullness")
public class RandomName {
private static final Random random = new Random();

Expand Down
1 change: 1 addition & 0 deletions key.util/src/main/java/org/key_project/util/Streams.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.io.InputStream;

@SuppressWarnings("nullness")
public class Streams {

private Streams() {
Expand Down
46 changes: 13 additions & 33 deletions key.util/src/main/java/org/key_project/util/Strings.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,33 @@
package org.key_project.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.key_project.util.java.StringUtil;

import org.jspecify.annotations.NullMarked;

/**
* Helper functions for {@link String}s
*
* @author Alexander Weigl
* @version 1 (29.03.19)
*/
@NullMarked
public class Strings {
/**
* Checks whether a string contains another one as a whole word (i.e., separated by whitespaces
* or a semicolon at the end).
*
* @param s string to search in
* @param word string to be searched for
* @deprecated This class has been merged with {@link org.key_project.util.java.StringUtil}.
* Call
* {@link org.key_project.util.java.StringUtil#containsWholeWord(String, String)}
*/
@Deprecated
public static boolean containsWholeWord(String s, String word) {
Pattern p = Pattern.compile("\\b" + word + "\\b");
Matcher m = p.matcher(s);
return m.find();
/*
* if (s == null || word == null) { return false; } int i = -1; final int wl =
* word.length(); while (true) { i = s.indexOf(word, i + 1); if (i < 0 || i >= s.length())
* break; if (i == 0 || Character.isWhitespace(s.charAt(i - 1))) { if (i + wl == s.length()
* || Character.isWhitespace(s.charAt(i + wl)) || s.charAt(i + wl) == ';') { return true; }
* } } return false;
*/
return StringUtil.containsWholeWord(s, word);
}


/**
* There are different kinds of JML markers. See Section 4.4 "Annotation markers" of the JML
* reference manual.
*
* @param comment
* @return
* @deprecated This class has been merged with {@link org.key_project.util.java.StringUtil}.
* Call {@link org.key_project.util.java.StringUtil#isJMLComment(String)}
*/
@Deprecated
public static boolean isJMLComment(String comment) {
try {
return (comment.startsWith("/*@") || comment.startsWith("//@")
|| comment.startsWith("/*+KeY@") || comment.startsWith("//+KeY@")
|| (comment.startsWith("/*-") && !comment.startsWith("KeY", 3)
&& comment.contains("@"))
|| (comment.startsWith("//-") && !comment.startsWith("KeY", 3)
&& comment.contains("@")));
} catch (IndexOutOfBoundsException e) {
return false;
}
return StringUtil.isJMLComment(comment);
}
}
1 change: 1 addition & 0 deletions key.util/src/main/java/org/key_project/util/bean/Bean.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @author Martin Hentschel
* @see IBean
*/
@SuppressWarnings("nullness")
public class Bean implements IBean {
/**
* The used {@link PropertyChangeSupport}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* @author Dominic Scheurer
*/
@SuppressWarnings("nullness")
public class ImmutableFixedLengthBitSet {

private boolean[] bitSet = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*
* @author Arne Keller
*/
@SuppressWarnings("nullness")
public class DefaultEdge implements GraphEdge {
/**
* Source node of this edge.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* This class implements ImmMap<S,T> and provides a persistent Map. It is a simple implementation
* like lists
*/
@SuppressWarnings("nullness")
public class DefaultImmutableMap<S, T> implements ImmutableMap<S, T> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
* @param <T> type of object to store
*/
@SuppressWarnings("nullness")
public class DefaultImmutableSet<T> implements ImmutableSet<T> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @param <E> edge type
* @author Arne Keller
*/
@SuppressWarnings("nullness")
public class DirectedGraph<V, E extends GraphEdge> implements Graph<V, E> {
/**
* Set of vertices in this graph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.stream.StreamSupport;
import javax.annotation.Nonnull;

@SuppressWarnings("nullness")
public class ImmutableArray<S> implements java.lang.Iterable<S>, java.io.Serializable {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* This class implements the leftist heap, see &quot;Functional Data Structures&quot; by Chris
* Okasaki
*/
@SuppressWarnings("nullness")
public abstract class ImmutableLeftistHeap<T extends Comparable<T>> implements ImmutableHeap<T> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* and head with amortized O(1). This will be done later (if necessary).
*/

@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "nullness" })
public abstract class ImmutableSLList<T> implements ImmutableList<T> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* offer a public static final variable .<called>nil()
*/

@SuppressWarnings("nullness")
public interface ImmutableSet<T> extends Iterable<T>, java.io.Serializable {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* @author Mattias Ulbrich
*/
@SuppressWarnings("nullness")
public final class Immutables {

private Immutables() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @author Alexander Weigl
* @version 1 (29.03.19)
*/
@SuppressWarnings("nullness")
public class KeYCollections {
// =======================================================
// Methods operating on Arrays
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


/** thrown if a duplicate is being added via addUnique() */
@SuppressWarnings("nullness")
public class NotUniqueException extends Exception {

private static final long serialVersionUID = 6565515240836947955L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.nio.charset.StandardCharsets;
import java.util.Properties;

@SuppressWarnings("nullness")
public class PropertiesUtil {

private PropertiesUtil() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @author Alexander Weigl
* @version 1 (13.02.19)
*/
@SuppressWarnings("nullness")
public final class FindResources {
/**
* List directory contents for a resource folder. Not recursive. This is basically a brute-force
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@SuppressWarnings("nullness")
public class HelperClassForUtilityTests {
public static final File RESOURCE_DIRECTORY = FindResources.getTestResourcesDirectory();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*
* @author Martin Hentschel
*/
@SuppressWarnings("nullness")
public final class ArrayUtil {
/**
* Forbid instances by this private constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*
* @author Martin Hentschel
*/
@SuppressWarnings("nullness")
public class CollectionUtil {
/**
* The default separator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*
* @author Martin Hentschel
*/
@SuppressWarnings("nullness")
public final class IOUtil {
/**
* The size of used buffers.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.key_project.util.java;

@SuppressWarnings("nullness")
public final class IntegerUtil {
/**
* Forbid instances.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*
* @author lanzinger
*/
@SuppressWarnings("nullness")
public final class MapUtil {

private MapUtil() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*
* @author Martin Hentschel
*/
@SuppressWarnings("nullness")
public class NumberUtil {
/**
* The maximal number of digits of an integer value.
Expand Down
Loading