Skip to content

Commit 436ca2c

Browse files
committed
chore: consolidate on jspecify nullability annotations
Signed-off-by: Chad Wilson <29788154+chadlwilson@users.noreply.github.com>
1 parent 568cdeb commit 436ca2c

File tree

24 files changed

+121
-128
lines changed

24 files changed

+121
-128
lines changed

core/src/main/java/org/owasp/dependencycheck/Engine.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2121
import org.apache.commons.jcs3.JCS;
22-
import org.jetbrains.annotations.NotNull;
23-
import org.jetbrains.annotations.Nullable;
22+
import org.jspecify.annotations.NonNull;
23+
import org.jspecify.annotations.Nullable;
2424
import org.owasp.dependencycheck.analyzer.AnalysisPhase;
2525
import org.owasp.dependencycheck.analyzer.Analyzer;
2626
import org.owasp.dependencycheck.analyzer.AnalyzerService;
@@ -145,7 +145,7 @@ public class Engine implements FileFilter, AutoCloseable {
145145
*
146146
* @param settings reference to the configured settings
147147
*/
148-
public Engine(@NotNull final Settings settings) {
148+
public Engine(@NonNull final Settings settings) {
149149
this(Mode.STANDALONE, settings);
150150
}
151151

@@ -155,7 +155,7 @@ public Engine(@NotNull final Settings settings) {
155155
* @param mode the mode of operation
156156
* @param settings reference to the configured settings
157157
*/
158-
public Engine(@NotNull final Mode mode, @NotNull final Settings settings) {
158+
public Engine(@NonNull final Mode mode, @NonNull final Settings settings) {
159159
this(Thread.currentThread().getContextClassLoader(), mode, settings);
160160
}
161161

@@ -165,7 +165,7 @@ public Engine(@NotNull final Mode mode, @NotNull final Settings settings) {
165165
* @param serviceClassLoader a reference the class loader being used
166166
* @param settings reference to the configured settings
167167
*/
168-
public Engine(@NotNull final ClassLoader serviceClassLoader, @NotNull final Settings settings) {
168+
public Engine(@NonNull final ClassLoader serviceClassLoader, @NonNull final Settings settings) {
169169
this(serviceClassLoader, Mode.STANDALONE, settings);
170170
}
171171

@@ -176,7 +176,7 @@ public Engine(@NotNull final ClassLoader serviceClassLoader, @NotNull final Sett
176176
* @param mode the mode of the engine
177177
* @param settings reference to the configured settings
178178
*/
179-
public Engine(@NotNull final ClassLoader serviceClassLoader, @NotNull final Mode mode, @NotNull final Settings settings) {
179+
public Engine(@NonNull final ClassLoader serviceClassLoader, @NonNull final Mode mode, @NonNull final Settings settings) {
180180
this.settings = settings;
181181
this.serviceClassLoader = serviceClassLoader;
182182
this.mode = mode;
@@ -277,7 +277,7 @@ public synchronized void sortDependencies() {
277277
*
278278
* @param dependency the dependency to remove.
279279
*/
280-
public synchronized void removeDependency(@NotNull final Dependency dependency) {
280+
public synchronized void removeDependency(@NonNull final Dependency dependency) {
281281
dependencies.remove(dependency);
282282
dependenciesExternalView = null;
283283
}
@@ -300,7 +300,7 @@ public synchronized Dependency[] getDependencies() {
300300
*
301301
* @param dependencies the dependencies
302302
*/
303-
public synchronized void setDependencies(@NotNull final List<Dependency> dependencies) {
303+
public synchronized void setDependencies(@NonNull final List<Dependency> dependencies) {
304304
this.dependencies.clear();
305305
this.dependencies.addAll(dependencies);
306306
dependenciesExternalView = null;
@@ -315,7 +315,7 @@ public synchronized void setDependencies(@NotNull final List<Dependency> depende
315315
* @return the list of dependencies scanned
316316
* @since v0.3.2.5
317317
*/
318-
public List<Dependency> scan(@NotNull final String[] paths) {
318+
public List<Dependency> scan(@NonNull final String[] paths) {
319319
return scan(paths, null);
320320
}
321321

@@ -330,7 +330,7 @@ public List<Dependency> scan(@NotNull final String[] paths) {
330330
* @return the list of dependencies scanned
331331
* @since v1.4.4
332332
*/
333-
public List<Dependency> scan(@NotNull final String[] paths, @Nullable final String projectReference) {
333+
public List<Dependency> scan(@NonNull final String[] paths, @Nullable final String projectReference) {
334334
final List<Dependency> deps = new ArrayList<>();
335335
for (String path : paths) {
336336
final List<Dependency> d = scan(path, projectReference);
@@ -349,7 +349,7 @@ public List<Dependency> scan(@NotNull final String[] paths, @Nullable final Stri
349349
* @param path the path to a file or directory to be analyzed
350350
* @return the list of dependencies scanned
351351
*/
352-
public List<Dependency> scan(@NotNull final String path) {
352+
public List<Dependency> scan(@NonNull final String path) {
353353
return scan(path, null);
354354
}
355355

@@ -364,7 +364,7 @@ public List<Dependency> scan(@NotNull final String path) {
364364
* @return the list of dependencies scanned
365365
* @since v1.4.4
366366
*/
367-
public List<Dependency> scan(@NotNull final String path, String projectReference) {
367+
public List<Dependency> scan(@NonNull final String path, String projectReference) {
368368
final File file = new File(path);
369369
return scan(file, projectReference);
370370
}
@@ -461,7 +461,7 @@ public List<Dependency> scan(File file) {
461461
* @since v1.4.4
462462
*/
463463
@Nullable
464-
public List<Dependency> scan(@NotNull final File file, String projectReference) {
464+
public List<Dependency> scan(@NonNull final File file, String projectReference) {
465465
if (file.exists()) {
466466
if (file.isDirectory()) {
467467
return scanDirectory(file, projectReference);
@@ -498,7 +498,7 @@ protected List<Dependency> scanDirectory(File dir) {
498498
* @return the list of Dependency objects scanned
499499
* @since v1.4.4
500500
*/
501-
protected List<Dependency> scanDirectory(@NotNull final File dir, @Nullable final String projectReference) {
501+
protected List<Dependency> scanDirectory(@NonNull final File dir, @Nullable final String projectReference) {
502502
final File[] files = dir.listFiles();
503503
final List<Dependency> deps = new ArrayList<>();
504504
if (files != null) {
@@ -526,7 +526,7 @@ protected List<Dependency> scanDirectory(@NotNull final File dir, @Nullable fina
526526
* @param file The file to scan
527527
* @return the scanned dependency
528528
*/
529-
protected Dependency scanFile(@NotNull final File file) {
529+
protected Dependency scanFile(@NonNull final File file) {
530530
return scanFile(file, null);
531531
}
532532

@@ -541,7 +541,7 @@ protected Dependency scanFile(@NotNull final File file) {
541541
* @return the scanned dependency
542542
* @since v1.4.4
543543
*/
544-
protected synchronized Dependency scanFile(@NotNull final File file, @Nullable final String projectReference) {
544+
protected synchronized Dependency scanFile(@NonNull final File file, @Nullable final String projectReference) {
545545
Dependency dependency = null;
546546
if (file.isFile()) {
547547
if (accept(file)) {
@@ -681,7 +681,7 @@ public void analyzeDependencies() throws ExceptionCollection {
681681
* @param exceptions a collection to store non-fatal exceptions
682682
* @throws ExceptionCollection thrown if fatal exceptions occur
683683
*/
684-
private void initializeAndUpdateDatabase(@NotNull final List<Throwable> exceptions) throws ExceptionCollection {
684+
private void initializeAndUpdateDatabase(@NonNull final List<Throwable> exceptions) throws ExceptionCollection {
685685
if (!mode.isDatabaseRequired()) {
686686
return;
687687
}
@@ -741,7 +741,7 @@ private void throwFatalDatabaseException(DatabaseException ex, final List<Throwa
741741
* @param analyzer the analyzer to execute
742742
* @throws ExceptionCollection thrown if exceptions occurred during analysis
743743
*/
744-
protected void executeAnalysisTasks(@NotNull final Analyzer analyzer, List<Throwable> exceptions) throws ExceptionCollection {
744+
protected void executeAnalysisTasks(@NonNull final Analyzer analyzer, List<Throwable> exceptions) throws ExceptionCollection {
745745
LOGGER.debug("Starting {}", analyzer.getName());
746746
final List<AnalysisTask> analysisTasks = getAnalysisTasks(analyzer, exceptions);
747747
final ExecutorService executorService = getExecutorService(analyzer);
@@ -805,7 +805,7 @@ protected ExecutorService getExecutorService(Analyzer analyzer) {
805805
* @throws InitializationException thrown when there is a problem
806806
* initializing the analyzer
807807
*/
808-
protected void initializeAnalyzer(@NotNull final Analyzer analyzer) throws InitializationException {
808+
protected void initializeAnalyzer(@NonNull final Analyzer analyzer) throws InitializationException {
809809
try {
810810
LOGGER.debug("Initializing {}", analyzer.getName());
811811
analyzer.prepare(this);
@@ -837,7 +837,7 @@ protected void initializeAnalyzer(@NotNull final Analyzer analyzer) throws Initi
837837
*
838838
* @param analyzer the analyzer to close
839839
*/
840-
protected void closeAnalyzer(@NotNull final Analyzer analyzer) {
840+
protected void closeAnalyzer(@NonNull final Analyzer analyzer) {
841841
LOGGER.debug("Closing Analyzer '{}'", analyzer.getName());
842842
try {
843843
analyzer.close();
@@ -1029,7 +1029,7 @@ public CveDB getDatabase() {
10291029
*
10301030
* @return a list of Analyzers
10311031
*/
1032-
@NotNull
1032+
@NonNull
10331033
public List<Analyzer> getAnalyzers() {
10341034
final List<Analyzer> analyzerList = new ArrayList<>();
10351035
//insteae of forEach - we can just do a collect
@@ -1129,7 +1129,7 @@ public Mode getMode() {
11291129
*
11301130
* @param fta the file type analyzer to add
11311131
*/
1132-
protected void addFileTypeAnalyzer(@NotNull final FileTypeAnalyzer fta) {
1132+
protected void addFileTypeAnalyzer(@NonNull final FileTypeAnalyzer fta) {
11331133
this.fileTypeAnalyzers.add(fta);
11341134
}
11351135

@@ -1154,8 +1154,8 @@ private void ensureDataExists() throws NoDataException {
11541154
* @throws ExceptionCollection a collection of exceptions that occurred
11551155
* during analysis
11561156
*/
1157-
private void throwFatalExceptionCollection(String message, @NotNull final Throwable throwable,
1158-
@NotNull final List<Throwable> exceptions) throws ExceptionCollection {
1157+
private void throwFatalExceptionCollection(String message, @NonNull final Throwable throwable,
1158+
@NonNull final List<Throwable> exceptions) throws ExceptionCollection {
11591159
LOGGER.error(message);
11601160
LOGGER.debug("", throwable);
11611161
exceptions.add(throwable);
@@ -1212,7 +1212,7 @@ public void writeReports(String applicationName, File outputDir, String format,
12121212
@Deprecated
12131213
public synchronized void writeReports(String applicationName, @Nullable final String groupId,
12141214
@Nullable final String artifactId, @Nullable final String version,
1215-
@NotNull final File outputDir, String format) throws ReportException {
1215+
@NonNull final File outputDir, String format) throws ReportException {
12161216
writeReports(applicationName, groupId, artifactId, version, outputDir, format, null);
12171217
}
12181218

@@ -1233,7 +1233,7 @@ public synchronized void writeReports(String applicationName, @Nullable final St
12331233
*/
12341234
public synchronized void writeReports(String applicationName, @Nullable final String groupId,
12351235
@Nullable final String artifactId, @Nullable final String version,
1236-
@NotNull final File outputDir, String format, ExceptionCollection exceptions) throws ReportException {
1236+
@NonNull final File outputDir, String format, ExceptionCollection exceptions) throws ReportException {
12371237
if (mode == Mode.EVIDENCE_COLLECTION) {
12381238
throw new UnsupportedOperationException("Cannot generate report in evidence collection mode.");
12391239
}

core/src/main/java/org/owasp/dependencycheck/analyzer/AbstractSuppressionAnalyzer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@
3131
import java.util.regex.Pattern;
3232
import javax.annotation.concurrent.ThreadSafe;
3333

34-
import org.jetbrains.annotations.NotNull;
34+
import org.jspecify.annotations.NonNull;
3535
import org.owasp.dependencycheck.Engine;
3636
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
3737
import org.owasp.dependencycheck.data.update.HostedSuppressionsDataSource;
38-
import org.owasp.dependencycheck.data.update.exception.UpdateException;
3938
import org.owasp.dependencycheck.dependency.Dependency;
4039
import org.owasp.dependencycheck.exception.InitializationException;
4140
import org.owasp.dependencycheck.exception.WriteLockException;
@@ -219,7 +218,7 @@ private void loadPackagedSuppressionBaseData(final SuppressionParser parser, fin
219218
}
220219
}
221220

222-
private static @NotNull URL getPackagedFile(String packagedFileName) throws SuppressionParseException {
221+
private static @NonNull URL getPackagedFile(String packagedFileName) throws SuppressionParseException {
223222
final URL jarLocation = AbstractSuppressionAnalyzer.class.getProtectionDomain().getCodeSource().getLocation();
224223
String suppressionFileLocation = jarLocation.getFile();
225224
if (suppressionFileLocation.endsWith(".jar")) {

core/src/main/java/org/owasp/dependencycheck/analyzer/CPEAnalyzer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
import org.apache.lucene.search.Query;
4747
import org.apache.lucene.search.ScoreDoc;
4848
import org.apache.lucene.search.TopDocs;
49-
import org.jetbrains.annotations.NotNull;
50-
import org.jetbrains.annotations.Nullable;
49+
import org.jspecify.annotations.NonNull;
50+
import org.jspecify.annotations.Nullable;
5151
import org.owasp.dependencycheck.Engine;
5252
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
5353
import org.owasp.dependencycheck.data.cpe.CpeMemoryIndex;
@@ -1277,7 +1277,7 @@ public boolean equals(Object obj) {
12771277
* @return the natural ordering of IdentifierMatch
12781278
*/
12791279
@Override
1280-
public int compareTo(@NotNull IdentifierMatch o) {
1280+
public int compareTo(@NonNull IdentifierMatch o) {
12811281
return new CompareToBuilder()
12821282
.append(identifierConfidence, o.identifierConfidence)
12831283
.append(identifier, o.identifier)

core/src/main/java/org/owasp/dependencycheck/analyzer/HintAnalyzer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
package org.owasp.dependencycheck.analyzer;
1919

20-
import org.jetbrains.annotations.VisibleForTesting;
20+
import com.google.common.annotations.VisibleForTesting;
2121
import org.owasp.dependencycheck.Engine;
2222
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
2323
import org.owasp.dependencycheck.dependency.Dependency;

core/src/main/java/org/owasp/dependencycheck/analyzer/PnpmAuditAnalyzer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import org.apache.commons.collections4.MultiValuedMap;
2121
import org.apache.commons.collections4.multimap.HashSetValuedHashMap;
2222
import org.apache.commons.lang3.StringUtils;
23-
import org.jetbrains.annotations.NotNull;
2423
import org.json.JSONException;
2524
import org.json.JSONObject;
25+
import org.jspecify.annotations.NonNull;
2626
import org.owasp.dependencycheck.Engine;
2727
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
2828
import org.owasp.dependencycheck.analyzer.exception.SearchException;
@@ -281,7 +281,7 @@ private List<Advisory> analyzePackage(final File lockFile,
281281
}
282282
}
283283

284-
@NotNull
284+
@NonNull
285285
private NpmAuditParser getAuditParser() {
286286
return new NpmAuditParser();
287287
}

core/src/main/java/org/owasp/dependencycheck/data/nexus/NexusV3Search.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.apache.hc.core5.http.HttpEntity;
2525
import org.apache.hc.core5.http.HttpHeaders;
2626
import org.apache.hc.core5.http.message.BasicHeader;
27-
import org.jetbrains.annotations.Nullable;
27+
import org.jspecify.annotations.Nullable;
2828
import org.owasp.dependencycheck.utils.DownloadFailedException;
2929
import org.owasp.dependencycheck.utils.Downloader;
3030
import org.owasp.dependencycheck.utils.ForbiddenException;

core/src/main/java/org/owasp/dependencycheck/data/update/NvdApiDataSource.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
import java.util.function.Function;
5656
import java.util.zip.GZIPOutputStream;
5757

58-
import org.jetbrains.annotations.NotNull;
58+
import org.jspecify.annotations.NonNull;
5959
import org.owasp.dependencycheck.Engine;
6060
import org.owasp.dependencycheck.data.nvdcve.CveDB;
6161
import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
@@ -666,20 +666,20 @@ public FeedUrl withPattern(Function<Optional<String>, String> patternTransformer
666666
return new FeedUrl(url, patternTransformer.apply(Optional.ofNullable(pattern)));
667667
}
668668

669-
@NotNull String toFormattedUrlString(String formatArg) {
669+
@NonNull String toFormattedUrlString(String formatArg) {
670670
return url + MessageFormat.format(Optional.ofNullable(pattern).orElseThrow(), formatArg);
671671
}
672672

673-
@NotNull String toFormattedUrlString(int formatArg) {
673+
@NonNull String toFormattedUrlString(int formatArg) {
674674
return toFormattedUrlString(String.valueOf(formatArg));
675675
}
676676

677-
@NotNull URL toFormattedUrl(@NotNull String formatArg) throws MalformedURLException, URISyntaxException {
677+
@NonNull URL toFormattedUrl(@NonNull String formatArg) throws MalformedURLException, URISyntaxException {
678678
return new URI(toFormattedUrlString(formatArg)).toURL();
679679
}
680680

681681
@SuppressWarnings("SameParameterValue")
682-
@NotNull URL toSuffixedUrl(String suffix) throws MalformedURLException, URISyntaxException {
682+
@NonNull URL toSuffixedUrl(String suffix) throws MalformedURLException, URISyntaxException {
683683
return new URI(url + suffix).toURL();
684684
}
685685

@@ -705,7 +705,7 @@ protected static FeedUrl extractFromUrlOptionalPattern(String url) {
705705
return new FeedUrl(baseUrl, pattern);
706706
}
707707

708-
private static @NotNull Pair<Integer, Integer> toYearRange(Settings settings, ZonedDateTime now) {
708+
private static @NonNull Pair<Integer, Integer> toYearRange(Settings settings, ZonedDateTime now) {
709709
// for establishing the current year use the timezone where the new year starts first
710710
// as from that moment on CNAs might start assigning CVEs with the new year depending
711711
// on the CNA's timezone
@@ -714,11 +714,11 @@ protected static FeedUrl extractFromUrlOptionalPattern(String url) {
714714
return new Pair<>(startYear, endYear);
715715
}
716716

717-
private @NotNull ZonedDateTime getLastModifiedFor(int year) throws UpdateException {
717+
private @NonNull ZonedDateTime getLastModifiedFor(int year) throws UpdateException {
718718
return getLastModifiedFor(String.valueOf(year));
719719
}
720720

721-
private @NotNull ZonedDateTime getLastModifiedFor(String fileVersion) throws UpdateException {
721+
private @NonNull ZonedDateTime getLastModifiedFor(String fileVersion) throws UpdateException {
722722
try {
723723
String content = Downloader.getInstance().fetchContent(toFormattedUrl(fileVersion), UTF_8);
724724
Properties props = new Properties();

core/src/main/java/org/owasp/dependencycheck/dependency/Evidence.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.apache.commons.lang3.builder.CompareToBuilder;
2222
import org.apache.commons.lang3.builder.EqualsBuilder;
2323
import org.apache.commons.lang3.builder.HashCodeBuilder;
24-
import org.jetbrains.annotations.NotNull;
24+
import org.jspecify.annotations.NonNull;
2525

2626
import java.io.Serializable;
2727
import javax.annotation.concurrent.ThreadSafe;
@@ -235,7 +235,7 @@ public boolean equals(Object obj) {
235235
* @return an integer indicating the ordering of the two objects
236236
*/
237237
@Override
238-
public int compareTo(@NotNull Evidence o) {
238+
public int compareTo(@NonNull Evidence o) {
239239
return new CompareToBuilder()
240240
.append(this.source == null ? null : this.source.toLowerCase(), o.source == null ? null : o.source.toLowerCase())
241241
.append(this.name == null ? null : this.name.toLowerCase(), o.name == null ? null : o.name.toLowerCase())

core/src/main/java/org/owasp/dependencycheck/dependency/Reference.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.apache.commons.lang3.builder.CompareToBuilder;
2323
import org.apache.commons.lang3.builder.EqualsBuilder;
2424
import org.apache.commons.lang3.builder.HashCodeBuilder;
25-
import org.jetbrains.annotations.NotNull;
25+
import org.jspecify.annotations.NonNull;
2626

2727
/**
2828
* An external reference for a vulnerability. This contains a name, URL, and a
@@ -160,7 +160,7 @@ public int hashCode() {
160160
* @return an integer indicating the ordering of the two objects
161161
*/
162162
@Override
163-
public int compareTo(@NotNull Reference o) {
163+
public int compareTo(@NonNull Reference o) {
164164
return new CompareToBuilder()
165165
.append(source, o.source)
166166
.append(name, o.name)

0 commit comments

Comments
 (0)