Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public Object id2019_type_NO_ANNOTATION_level_PACKAGE(
return new Object();
}


}

abstract class NullabilityAtMethodLevelParent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ public class NullabilityAtVariableLevel {
Object id1031_type_NON_NULL_level_VARIABLE;
@javax.annotation.Nonnull
Object id1032_type_NON_NULL_level_VARIABLE;
@javax.validation.constraints.NotNull
Object id1033_type_NON_NULL_level_VARIABLE;
@lombok.NonNull
Object id1034_type_NON_NULL_level_VARIABLE;
@org.checkerframework.checker.nullness.compatqual.NonNullDecl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,6 @@ public boolean equals(@Nonnull C c) { // Compliant
}
}

static class F {
public boolean equals(
@javax.validation.constraints.NotNull // Noncompliant {{"equals" method parameters should not be marked "@NotNull".}} [[quickfixes=qf2]]
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
java.lang.Object object) {
// fix@qf2 {{Remove "@NotNull"}}
// edit@qf2 [[sc=7;ec=7;el=+2]] {{}}
return false;
}
}

@org.eclipse.jdt.annotation.NonNullByDefault
static class G {
public boolean equals(Object object) { // Compliant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,38 +186,6 @@ void argAnnotatedDirectlyNullable(@MyNonnullMetaAnnotation Object a) { } // Nonc
}
}

/**
* Not null with arguments is inconsistently supported. See SONARJAVA-3803.
*/
class ChangeMethodContractCheck_NonnullWithArguments {

class Parent {
@javax.validation.constraints.NotNull(groups = { ChangeMethodContractCheck.class })
String annotatedNotNullWithArg(Object a) { return "null"; }

@javax.validation.constraints.NotNull
String annotatedNotNullWithoutArg(Object a) { return "null"; }

void argAnnotatedNoNullWithArg(@javax.validation.constraints.NotNull(groups = { ChangeMethodContractCheck.class }) Object a) { }
void argAnnotatedNoNullWithoutArg(@javax.validation.constraints.NotNull Object a) { }
}

class Child extends Parent {
// Parent is not strictly not null (NotNull with arguments).
@Override
@javax.annotation.CheckForNull
String annotatedNotNullWithArg(Object a) { return null; }

@Override
// This one is a TP though.
@javax.annotation.CheckForNull
String annotatedNotNullWithoutArg(Object a) { return null; } // Noncompliant {{Fix the incompatibility of the annotation @CheckForNull to honor @NotNull of the overridden method.}}

// It works correctly for arguments though.
void argAnnotatedNoNullWithArg(@javax.annotation.CheckForNull Object a) { }
void argAnnotatedNoNullWithoutArg(@javax.annotation.CheckForNull Object a) { }
}
}

/**
* javax.annotation.Nonnull with argument when=When.MAYBE or when=When.UNKNOWN is actually Nullable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.List;
import javax.annotation.meta.When;
import javax.validation.constraints.NotNull;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.NullUnmarked;
Expand All @@ -20,11 +19,6 @@ public void methodNonNullParam(@javax.annotation.Nonnull(when= When.ALWAYS) Obje
// ...
}

@NotNull // Noncompliant {{Remove redundant annotation @NotNull as inside scope annotation @NullMarked at class level.}}
public Integer methodJXNonNullReturn(Object o) {
return 0;
}

@javax.annotation.Nonnull(when= When.ALWAYS) // Noncompliant {{Remove redundant annotation @Nonnull(when=ALWAYS) as inside scope annotation @NullMarked at class level.}}
public Integer methodNonNullReturn(Object o) {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ private void checkContractChange(MethodTree methodTree, Symbol.MethodSymbol over

private void compareNullability(TypeTree tree, SymbolMetadata upperBound, SymbolMetadata lowerBound, boolean overriddenIsLowerBound) {
// Check current level
if (upperBound.nullabilityData().isNullable(PACKAGE, false, false)
&& lowerBound.nullabilityData().isNonNull(PACKAGE, false, false)) {
reportIssue(tree, lowerBound.nullabilityData(), upperBound.nullabilityData(), overriddenIsLowerBound);
NullabilityData upperData = upperBound.nullabilityData();
NullabilityData lowerData = lowerBound.nullabilityData();
if (upperData.isNullable(PACKAGE, false, false)
&& lowerData.isNonNull(PACKAGE, false, false)) {
reportIssue(tree, lowerData, upperData, overriddenIsLowerBound);
}

// Check type parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ private JSymbolMetadataNullabilityHelper() {
"edu.umd.cs.findbugs.annotations.NonNull",
"io.reactivex.annotations.NonNull",
"io.reactivex.rxjava3.annotations.NonNull",
"javax.validation.constraints.NotNull",
"jakarta.validation.constraints.NotNull",
"lombok.NonNull",
"org.checkerframework.checker.nullness.compatqual.NonNullDecl",
"org.checkerframework.checker.nullness.compatqual.NonNullType",
Expand Down
Loading