Skip to content

Commit fe8883d

Browse files
committed
Move nullability declaration to type parameter
1 parent 2b180cd commit fe8883d

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

junit-platform-commons/src/main/java/org/junit/platform/commons/support/conversion/Converter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* @see TypedConverter
3838
*/
3939
@API(status = EXPERIMENTAL, since = "6.0")
40-
public interface Converter<S, T> {
40+
public interface Converter<S, T extends @Nullable Object> {
4141

4242
/**
4343
* Determine if the supplied conversion context is supported.
@@ -59,7 +59,6 @@ public interface Converter<S, T> {
5959
* type is a reference type
6060
* @throws ConversionException if an error occurs during the conversion
6161
*/
62-
@Nullable
6362
T convert(@Nullable S source, ConversionContext context) throws ConversionException;
6463

6564
}

junit-platform-commons/src/main/java/org/junit/platform/commons/support/conversion/DefaultConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
* @since 6.0
4545
*/
4646
@API(status = INTERNAL, since = "6.0")
47-
public class DefaultConverter implements Converter<String, Object> {
47+
public class DefaultConverter implements Converter<String, @Nullable Object> {
4848

4949
static final DefaultConverter INSTANCE = new DefaultConverter();
5050

junit-platform-commons/src/main/java/org/junit/platform/commons/support/conversion/FallbackStringToObjectConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
* @since 1.11
5353
* @see ConversionSupport
5454
*/
55-
class FallbackStringToObjectConverter extends StringToTargetTypeConverter<Object> {
55+
class FallbackStringToObjectConverter extends StringToTargetTypeConverter<@Nullable Object> {
5656

5757
/**
5858
* Implementation of the NULL Object Pattern.

junit-platform-commons/src/main/java/org/junit/platform/commons/support/conversion/StringToTargetTypeConverter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Internal API for converting arguments of type {@link String} to a specified
1818
* target type.
1919
*/
20-
abstract class StringToTargetTypeConverter<T> implements Converter<String, T> {
20+
abstract class StringToTargetTypeConverter<T extends @Nullable Object> implements Converter<String, T> {
2121

2222
@Override
2323
public final boolean canConvert(ConversionContext context) {
@@ -31,7 +31,7 @@ public final boolean canConvert(ConversionContext context) {
3131
abstract boolean canConvert(Class<?> targetType);
3232

3333
@Override
34-
public final @Nullable T convert(@Nullable String source, ConversionContext context) {
34+
public final T convert(@Nullable String source, ConversionContext context) {
3535
Preconditions.notNull(source, "source cannot be null");
3636
return convert(source, context.targetType().getType());
3737
}
@@ -42,6 +42,6 @@ public final boolean canConvert(ConversionContext context) {
4242
* <p>This method will only be invoked if {@link #canConvert(Class)}
4343
* returned {@code true} for the same target type.
4444
*/
45-
abstract @Nullable T convert(String source, Class<?> targetType);
45+
abstract T convert(String source, Class<?> targetType);
4646

4747
}

junit-platform-commons/src/main/java/org/junit/platform/commons/support/conversion/TypedConverter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* @since 6.0
2727
*/
2828
@API(status = EXPERIMENTAL, since = "6.0")
29-
public abstract class TypedConverter<S, T> implements Converter<S, T> {
29+
public abstract class TypedConverter<S, T extends @Nullable Object> implements Converter<S, T> {
3030

3131
private final Class<S> sourceType;
3232
private final Class<T> targetType;
@@ -45,12 +45,13 @@ protected TypedConverter(Class<S> sourceType, Class<T> targetType) {
4545

4646
@Override
4747
public final boolean canConvert(ConversionContext context) {
48+
// FIXME TypeDescriptor.NONE handling?
4849
// FIXME add test cases with subtypes
4950
return this.sourceType == context.sourceType().getType() && this.targetType == context.targetType().getType();
5051
}
5152

5253
@Override
53-
public final @Nullable T convert(@Nullable S source, ConversionContext context) {
54+
public final T convert(@Nullable S source, ConversionContext context) {
5455
return convert(source);
5556
}
5657

@@ -63,6 +64,6 @@ public final boolean canConvert(ConversionContext context) {
6364
* type is a reference type
6465
* @throws ConversionException if an error occurs during the conversion
6566
*/
66-
protected abstract @Nullable T convert(@Nullable S source) throws ConversionException;
67+
protected abstract T convert(@Nullable S source) throws ConversionException;
6768

6869
}

0 commit comments

Comments
 (0)