Skip to content

Commit

Permalink
resolve issues identified by SpotBugs
Browse files Browse the repository at this point in the history
blasted null checks are ugly but oh well
  • Loading branch information
copart-jafloyd committed Aug 31, 2023
1 parent c772bc0 commit b4bde02
Showing 1 changed file with 36 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,24 @@ public Artifact(RepositoryEvent event, RepositoryLayout repositoryLayout) {
try {
// getLocation returns a URI instance that ONLY has a path (no scheme, host, ...)
URI downloadLocation = repositoryLayout.getLocation(artifact, false);
downloadPath = downloadLocation.getPath();
if (downloadPath == null) {
downloadPath = "";
} else {
downloadFileName = Paths.get(downloadPath).getFileName().toString();

URI repoUri = new URI(((RemoteRepository) repository).getUrl());
downloadUrl = new URI(
repoUri.getScheme(),
null, // drop any userInfo (user:password)
repoUri.getHost(),
repoUri.getPort(),
repoUri.resolve(downloadLocation).getPath(),
repoUri.getQuery(),
repoUri.getFragment()
).toString();
if (downloadLocation != null) {
downloadPath = downloadLocation.getPath();
if (downloadPath == null) {
downloadPath = "";
} else {
downloadFileName = Paths.get(downloadPath).getFileName().toString();

Check warning on line 93 in src/main/java/org/jvnet/hudson/plugins/repositoryconnector/aether/RecorderAction.java

View check run for this annotation

ci.jenkins.io / SpotBugs

NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

NORMAL: Possible null pointer dereference in new org.jvnet.hudson.plugins.repositoryconnector.aether.RecorderAction$Artifact(RepositoryEvent, RepositoryLayout) due to return value of called method
Raw output
<p> The return value from a method is dereferenced without a null check, and the return value of that method is one that should generally be checked for null. This may lead to a <code>NullPointerException</code> when the code is executed. </p>

URI repoUri = new URI(((RemoteRepository) repository).getUrl());
downloadUrl = new URI(
repoUri.getScheme(),
null, // drop any userInfo (user:password)
repoUri.getHost(),
repoUri.getPort(),
repoUri.resolve(downloadLocation).getPath(),
repoUri.getQuery(),
repoUri.getFragment()
).toString();
}
}
} catch (URISyntaxException ignored) {
}
Expand Down Expand Up @@ -213,22 +215,24 @@ public Metadata(RepositoryEvent event, RepositoryLayout repositoryLayout) {
try {
// getLocation returns a URI instance that ONLY has a path (no scheme, host, ...)
URI downloadLocation = repositoryLayout.getLocation(metadata, false);
downloadPath = downloadLocation.getPath();
if (downloadPath == null) {
downloadPath = "";
} else {
downloadFileName = Paths.get(downloadPath).getFileName().toString();

URI repoUri = new URI(((RemoteRepository) repository).getUrl());
downloadUrl = new URI(
repoUri.getScheme(),
null, // drop any userInfo (user:password)
repoUri.getHost(),
repoUri.getPort(),
repoUri.resolve(downloadLocation).getPath(),
repoUri.getQuery(),
repoUri.getFragment()
).toString();
if (downloadLocation != null) {
downloadPath = downloadLocation.getPath();
if (downloadPath == null) {
downloadPath = "";
} else {
downloadFileName = Paths.get(downloadPath).getFileName().toString();

Check warning on line 223 in src/main/java/org/jvnet/hudson/plugins/repositoryconnector/aether/RecorderAction.java

View check run for this annotation

ci.jenkins.io / SpotBugs

NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

NORMAL: Possible null pointer dereference in new org.jvnet.hudson.plugins.repositoryconnector.aether.RecorderAction$Metadata(RepositoryEvent, RepositoryLayout) due to return value of called method
Raw output
<p> The return value from a method is dereferenced without a null check, and the return value of that method is one that should generally be checked for null. This may lead to a <code>NullPointerException</code> when the code is executed. </p>

URI repoUri = new URI(((RemoteRepository) repository).getUrl());
downloadUrl = new URI(
repoUri.getScheme(),
null, // drop any userInfo (user:password)
repoUri.getHost(),
repoUri.getPort(),
repoUri.resolve(downloadLocation).getPath(),
repoUri.getQuery(),
repoUri.getFragment()
).toString();
}
}
} catch (URISyntaxException ignored) {
}
Expand Down

0 comments on commit b4bde02

Please sign in to comment.