Skip to content

Commit 69df514

Browse files
committed
Annotate nullability in org.junit.platform.engine
1 parent a1b5879 commit 69df514

File tree

11 files changed

+50
-19
lines changed

11 files changed

+50
-19
lines changed

junit-platform-engine/src/main/java/org/junit/platform/engine/DefaultDiscoveryIssue.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.Objects;
1414
import java.util.Optional;
1515

16+
import org.jspecify.annotations.Nullable;
1617
import org.junit.platform.commons.util.ToStringBuilder;
1718

1819
/**
@@ -22,7 +23,11 @@ final class DefaultDiscoveryIssue implements DiscoveryIssue {
2223

2324
private final Severity severity;
2425
private final String message;
26+
27+
@Nullable
2528
private final TestSource source;
29+
30+
@Nullable
2631
private final Throwable cause;
2732

2833
DefaultDiscoveryIssue(Builder builder) {
@@ -86,7 +91,11 @@ static class Builder implements DiscoveryIssue.Builder {
8691

8792
private final Severity severity;
8893
private final String message;
94+
95+
@Nullable
8996
private TestSource source;
97+
98+
@Nullable
9099
public Throwable cause;
91100

92101
Builder(Severity severity, String message) {
@@ -95,13 +104,13 @@ static class Builder implements DiscoveryIssue.Builder {
95104
}
96105

97106
@Override
98-
public Builder source(TestSource source) {
107+
public Builder source(@Nullable TestSource source) {
99108
this.source = source;
100109
return this;
101110
}
102111

103112
@Override
104-
public Builder cause(Throwable cause) {
113+
public Builder cause(@Nullable Throwable cause) {
105114
this.cause = cause;
106115
return this;
107116
}

junit-platform-engine/src/main/java/org/junit/platform/engine/DiscoveryIssue.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.function.UnaryOperator;
1717

1818
import org.apiguardian.api.API;
19+
import org.jspecify.annotations.Nullable;
1920
import org.junit.platform.commons.util.Preconditions;
2021

2122
/**
@@ -138,7 +139,7 @@ default Builder source(Optional<TestSource> source) {
138139
* @param source the {@link TestSource} for the {@code DiscoveryIssue};
139140
* may be {@code null}
140141
*/
141-
Builder source(TestSource source);
142+
Builder source(@Nullable TestSource source);
142143

143144
/**
144145
* Set the {@link Throwable} that caused the {@code DiscoveryIssue}.
@@ -157,7 +158,7 @@ default Builder cause(Optional<Throwable> cause) {
157158
* @param cause the {@link Throwable} that caused the
158159
* {@code DiscoveryIssue}; may be {@code null}
159160
*/
160-
Builder cause(Throwable cause);
161+
Builder cause(@Nullable Throwable cause);
161162

162163
/**
163164
* Build the {@code DiscoveryIssue}.

junit-platform-engine/src/main/java/org/junit/platform/engine/EngineDiscoveryRequest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public interface EngineDiscoveryRequest {
4646
* Get the {@link DiscoverySelector DiscoverySelectors} for this request,
4747
* filtered by a particular type.
4848
*
49-
* @param selectorType the type of {@link DiscoverySelector} to filter by
49+
* @param selectorType the type of {@link DiscoverySelector} to filter by;
50+
* never {@code null}
5051
* @return all selectors of this request that are instances of
5152
* {@code selectorType}; never {@code null} but potentially empty
5253
*/
@@ -59,7 +60,8 @@ public interface EngineDiscoveryRequest {
5960
* <p>The returned filters are to be combined using AND semantics, i.e. all
6061
* of them have to include a resource for it to end up in the test plan.
6162
*
62-
* @param filterType the type of {@link DiscoveryFilter} to filter by
63+
* @param filterType the type of {@link DiscoveryFilter} to filter by;
64+
* never {@code null}
6365
* @return all filters of this request that are instances of
6466
* {@code filterType}; never {@code null} but potentially empty
6567
*/

junit-platform-engine/src/main/java/org/junit/platform/engine/ExecutionRequest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import static org.apiguardian.api.API.Status.STABLE;
1717

1818
import org.apiguardian.api.API;
19+
import org.jspecify.annotations.Nullable;
1920
import org.junit.platform.commons.PreconditionViolationException;
2021
import org.junit.platform.commons.util.Preconditions;
2122
import org.junit.platform.engine.reporting.OutputDirectoryProvider;
@@ -41,7 +42,11 @@ public class ExecutionRequest {
4142
private final TestDescriptor rootTestDescriptor;
4243
private final EngineExecutionListener engineExecutionListener;
4344
private final ConfigurationParameters configurationParameters;
45+
46+
@Nullable
4447
private final OutputDirectoryProvider outputDirectoryProvider;
48+
49+
@Nullable
4550
private final NamespacedHierarchicalStore<Namespace> requestLevelStore;
4651

4752
@Deprecated
@@ -52,8 +57,8 @@ public ExecutionRequest(TestDescriptor rootTestDescriptor, EngineExecutionListen
5257
}
5358

5459
private ExecutionRequest(TestDescriptor rootTestDescriptor, EngineExecutionListener engineExecutionListener,
55-
ConfigurationParameters configurationParameters, OutputDirectoryProvider outputDirectoryProvider,
56-
NamespacedHierarchicalStore<Namespace> requestLevelStore) {
60+
ConfigurationParameters configurationParameters, @Nullable OutputDirectoryProvider outputDirectoryProvider,
61+
@Nullable NamespacedHierarchicalStore<Namespace> requestLevelStore) {
5762
this.rootTestDescriptor = Preconditions.notNull(rootTestDescriptor, "rootTestDescriptor must not be null");
5863
this.engineExecutionListener = Preconditions.notNull(engineExecutionListener,
5964
"engineExecutionListener must not be null");

junit-platform-engine/src/main/java/org/junit/platform/engine/FilterResult.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.function.Supplier;
1717

1818
import org.apiguardian.api.API;
19+
import org.jspecify.annotations.Nullable;
1920
import org.junit.platform.commons.util.ToStringBuilder;
2021

2122
/**
@@ -32,7 +33,7 @@ public class FilterResult {
3233
* @param reason the reason why the filtered object was included
3334
* @return an included {@code FilterResult} with the given reason
3435
*/
35-
public static FilterResult included(String reason) {
36+
public static FilterResult included(@Nullable String reason) {
3637
return new FilterResult(true, reason);
3738
}
3839

@@ -42,14 +43,14 @@ public static FilterResult included(String reason) {
4243
* @param reason the reason why the filtered object was excluded
4344
* @return an excluded {@code FilterResult} with the given reason
4445
*/
45-
public static FilterResult excluded(String reason) {
46+
public static FilterResult excluded(@Nullable String reason) {
4647
return new FilterResult(false, reason);
4748
}
4849

4950
/**
5051
* Factory for creating filter results based on the condition given.
5152
*
52-
* @param included whether or not the filtered object should be included
53+
* @param included whether the filtered object should be included
5354
* @return a valid {@code FilterResult} for the given condition
5455
*/
5556
public static FilterResult includedIf(boolean included) {
@@ -59,21 +60,21 @@ public static FilterResult includedIf(boolean included) {
5960
/**
6061
* Factory for creating filter results based on the condition given.
6162
*
62-
* @param included whether or not the filtered object should be included
63+
* @param included whether the filtered object should be included
6364
* @param inclusionReasonSupplier supplier for the reason in case of inclusion
6465
* @param exclusionReasonSupplier supplier for the reason in case of exclusion
6566
* @return a valid {@code FilterResult} for the given condition
6667
*/
67-
public static FilterResult includedIf(boolean included, Supplier<String> inclusionReasonSupplier,
68-
Supplier<String> exclusionReasonSupplier) {
68+
public static FilterResult includedIf(boolean included, Supplier<@Nullable String> inclusionReasonSupplier,
69+
Supplier<@Nullable String> exclusionReasonSupplier) {
6970
return included ? included(inclusionReasonSupplier.get()) : excluded(exclusionReasonSupplier.get());
7071
}
7172

7273
private final boolean included;
7374

7475
private final Optional<String> reason;
7576

76-
private FilterResult(boolean included, String reason) {
77+
private FilterResult(boolean included, @Nullable String reason) {
7778
this.included = included;
7879
this.reason = Optional.ofNullable(reason);
7980
}

junit-platform-engine/src/main/java/org/junit/platform/engine/SelectorResolutionResult.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.Optional;
1616

1717
import org.apiguardian.api.API;
18+
import org.jspecify.annotations.Nullable;
1819
import org.junit.platform.commons.util.ToStringBuilder;
1920

2021
/**
@@ -86,9 +87,11 @@ public static SelectorResolutionResult failed(Throwable throwable) {
8687
}
8788

8889
private final Status status;
90+
91+
@Nullable
8992
private final Throwable throwable;
9093

91-
private SelectorResolutionResult(Status status, Throwable throwable) {
94+
private SelectorResolutionResult(Status status, @Nullable Throwable throwable) {
9295
this.status = status;
9396
this.throwable = throwable;
9497
}

junit-platform-engine/src/main/java/org/junit/platform/engine/TestDescriptor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.function.UnaryOperator;
2323

2424
import org.apiguardian.api.API;
25+
import org.jspecify.annotations.Nullable;
2526
import org.junit.platform.commons.util.Preconditions;
2627

2728
/**
@@ -99,7 +100,7 @@ default String getLegacyReportingName() {
99100
*
100101
* @param parent the new parent of this descriptor; may be {@code null}.
101102
*/
102-
void setParent(TestDescriptor parent);
103+
void setParent(@Nullable TestDescriptor parent);
103104

104105
/**
105106
* Get the immutable set of <em>children</em> of this descriptor.

junit-platform-engine/src/main/java/org/junit/platform/engine/TestExecutionResult.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Optional;
1919

2020
import org.apiguardian.api.API;
21+
import org.jspecify.annotations.Nullable;
2122
import org.junit.platform.commons.util.Preconditions;
2223
import org.junit.platform.commons.util.ToStringBuilder;
2324

@@ -94,9 +95,11 @@ public static TestExecutionResult failed(Throwable throwable) {
9495
}
9596

9697
private final Status status;
98+
99+
@Nullable
97100
private final Throwable throwable;
98101

99-
private TestExecutionResult(Status status, Throwable throwable) {
102+
private TestExecutionResult(Status status, @Nullable Throwable throwable) {
100103
this.status = Preconditions.notNull(status, "Status must not be null");
101104
this.throwable = throwable;
102105
}

junit-platform-engine/src/main/java/org/junit/platform/engine/TestTag.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Set;
2222

2323
import org.apiguardian.api.API;
24+
import org.jspecify.annotations.Nullable;
2425
import org.junit.platform.commons.PreconditionViolationException;
2526
import org.junit.platform.commons.util.Preconditions;
2627
import org.junit.platform.commons.util.StringUtils;
@@ -84,7 +85,7 @@ public final class TestTag implements Serializable {
8485
* @see #RESERVED_CHARACTERS
8586
* @see TestTag#create(String)
8687
*/
87-
public static boolean isValid(String name) {
88+
public static boolean isValid(@Nullable String name) {
8889
if (name == null) {
8990
return false;
9091
}

junit-platform-engine/src/main/java/org/junit/platform/engine/UniqueId.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Optional;
2424

2525
import org.apiguardian.api.API;
26+
import org.jspecify.annotations.Nullable;
2627
import org.junit.platform.commons.JUnitException;
2728
import org.junit.platform.commons.util.Preconditions;
2829
import org.junit.platform.commons.util.ToStringBuilder;
@@ -92,6 +93,7 @@ public static UniqueId root(String segmentType, String value) {
9293
private transient int hashCode;
9394

9495
// lazily computed
96+
@Nullable
9597
private transient SoftReference<String> toString;
9698

9799
private UniqueId(UniqueIdFormat uniqueIdFormat, Segment segment) {

0 commit comments

Comments
 (0)