diff --git a/key.util/src/main/java/org/key_project/util/bean/Bean.java b/key.util/src/main/java/org/key_project/util/bean/Bean.java
index 04c5899a2ca..9eae6c0cb14 100644
--- a/key.util/src/main/java/org/key_project/util/bean/Bean.java
+++ b/key.util/src/main/java/org/key_project/util/bean/Bean.java
@@ -6,6 +6,9 @@
import org.key_project.util.java.ArrayUtil;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+
/**
* Implements the basic methods that a Java bean should have and is the default implementation of
* {@link IBean}.
@@ -13,11 +16,12 @@
* @author Martin Hentschel
* @see IBean
*/
-@SuppressWarnings("nullness")
+@NullMarked
public class Bean implements IBean {
/**
* The used {@link PropertyChangeSupport}.
*/
+ @SuppressWarnings("nullness") // TODO Check with Werner Dietl why this is so.
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
/**
@@ -127,8 +131,8 @@ protected void fireIndexedPropertyChange(String propertyName, int index, int old
* @param oldValue The old value.
* @param newValue The new value.
*/
- protected void fireIndexedPropertyChange(String propertyName, int index, Object oldValue,
- Object newValue) {
+ protected void fireIndexedPropertyChange(String propertyName, int index,
+ @Nullable Object oldValue, @Nullable Object newValue) {
pcs.fireIndexedPropertyChange(propertyName, index, oldValue, newValue);
}
diff --git a/key.util/src/main/java/org/key_project/util/bean/IBean.java b/key.util/src/main/java/org/key_project/util/bean/IBean.java
index 1706fcd6b16..ff71eb17169 100644
--- a/key.util/src/main/java/org/key_project/util/bean/IBean.java
+++ b/key.util/src/main/java/org/key_project/util/bean/IBean.java
@@ -2,6 +2,8 @@
import java.beans.PropertyChangeListener;
+import org.jspecify.annotations.NullMarked;
+
/**
*
* Defines the methods that a Java bean must have.
@@ -13,6 +15,7 @@
* @author Martin Hentschel
* @see Bean
*/
+@NullMarked
public interface IBean {
/**
* Adds the given listener.
diff --git a/key.util/src/main/java/org/key_project/util/java/ArrayUtil.java b/key.util/src/main/java/org/key_project/util/java/ArrayUtil.java
index 2ce18fcbbd2..5c5d780b656 100644
--- a/key.util/src/main/java/org/key_project/util/java/ArrayUtil.java
+++ b/key.util/src/main/java/org/key_project/util/java/ArrayUtil.java
@@ -1,13 +1,13 @@
package org.key_project.util.java;
-import org.jspecify.annotations.NullMarked;
-import org.jspecify.annotations.Nullable;
-
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+
/**
* Provides static methods to work with arrays.
*
@@ -60,25 +60,26 @@ private ArrayUtil() {
* @throws IllegalArgumentException Both parameters are {@code null}.
*/
@SuppressWarnings("unchecked")
- public static T [] addAll(T @Nullable [] array, T @Nullable [] toAdd) {
+ public static T[] addAll(T @Nullable [] array,
+ T @Nullable [] toAdd) {
if (array != null) {
if (toAdd != null) {
T[] result =
- (T[]) java.lang.reflect.Array.newInstance(array.getClass().getComponentType(),
+ (T[]) java.lang.reflect.Array.newInstance(getComponentType(array),
array.length + toAdd.length);
System.arraycopy(array, 0, result, 0, array.length);
System.arraycopy(toAdd, 0, result, array.length, toAdd.length);
return result;
} else {
T[] result = (T[]) java.lang.reflect.Array
- .newInstance(array.getClass().getComponentType(), array.length);
+ .newInstance(getComponentType(array), array.length);
System.arraycopy(array, 0, result, 0, array.length);
return result;
}
} else {
if (toAdd != null) {
T[] result = (T[]) java.lang.reflect.Array
- .newInstance(toAdd.getClass().getComponentType(), toAdd.length);
+ .newInstance(getComponentType(toAdd), toAdd.length);
System.arraycopy(toAdd, 0, result, 0, toAdd.length);
return result;
} else {
@@ -88,6 +89,12 @@ private ArrayUtil() {
}
}
+ private static Class extends T> getComponentType(T[] array) {
+ Class extends Object[]> arrayClass = array.getClass();
+ assert arrayClass.isArray() : "@AssumeAssertion(nullness): This is always the case";
+ return (Class extends T>) arrayClass.getComponentType();
+ }
+
/**
*
* Adds the given elements to the existing array. The result is a new array that contains the
@@ -105,7 +112,8 @@ private ArrayUtil() {
* @throws IllegalArgumentException Both parameters are {@code null}.
*/
@SuppressWarnings("unchecked")
- public static T[] addAll(T @Nullable [] array, T @Nullable [] toAdd, Class> newArrayType) {
+ public static T[] addAll(T @Nullable [] array,
+ T @Nullable [] toAdd, Class> newArrayType) {
if (array != null) {
if (toAdd != null) {
T[] result = (T[]) java.lang.reflect.Array.newInstance(newArrayType,
@@ -145,10 +153,12 @@ private ArrayUtil() {
* @throws IllegalArgumentException Both parameters are {@code null}.
*/
@SuppressWarnings("unchecked")
- public static T[] add(T @Nullable [] array, @Nullable T toAdd) {
+ public static @Nullable T[] add(T @Nullable [] array,
+ @Nullable T toAdd) {
if (array != null) {
- T[] result = (T[]) java.lang.reflect.Array
- .newInstance(array.getClass().getComponentType(), array.length + 1);
+ @Nullable
+ T[] result = (@Nullable T[]) java.lang.reflect.Array
+ .newInstance(getComponentType(array), array.length + 1);
System.arraycopy(array, 0, result, 0, array.length);
result[array.length] = toAdd;
return result;
@@ -200,7 +210,7 @@ public static int[] add(int[] array, int toAdd) {
public static T[] insert(T[] array, T toInsert, int index) {
if (array != null) {
T[] result = (T[]) java.lang.reflect.Array
- .newInstance(array.getClass().getComponentType(), array.length + 1);
+ .newInstance(getComponentType(array), array.length + 1);
if (index >= 1) {
System.arraycopy(array, 0, result, 0, index);
}
@@ -263,7 +273,8 @@ public static int indexOf(T[] array, T toSearch) {
* was {@code null}.
*/
@SuppressWarnings("unchecked")
- public static T[] remove(T[] array, T toRemove) {
+ public static T @Nullable [] remove(T @Nullable [] array,
+ @Nullable T toRemove) {
if (array != null) {
List result = new LinkedList<>();
for (T element : array) {
@@ -271,8 +282,8 @@ public static T[] remove(T[] array, T toRemove) {
result.add(element);
}
}
- return result.toArray((T[]) java.lang.reflect.Array
- .newInstance(array.getClass().getComponentType(), result.size()));
+ return (T[]) result.toArray((T[]) java.lang.reflect.Array
+ .newInstance(getComponentType(array), result.size()));
} else {
return null;
}