Skip to content

Commit

Permalink
PIP: Avoid to generically catch a NullPointerException
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schuberth <sebastian.schuberth@here.com>
  • Loading branch information
sschuberth committed Mar 26, 2019
1 parent 277297a commit 3bd9491
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions analyzer/src/main/kotlin/managers/PIP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -346,42 +346,40 @@ class PIP(name: String, analyzerConfig: AnalyzerConfiguration, repoConfig: Repos
return@use pkg
}

try {
val pkgInfo = pkgData["info"]

pkgData["info"]?.let { pkgInfo ->
val pkgDescription = pkgInfo["summary"]?.textValue() ?: pkg.description
val pkgHomepage = pkgInfo["home_page"]?.textValue() ?: pkg.homepageUrl

val pkgVersion = pkgData["releases"].fieldNames().asSequence().find {
stripLeadingZerosFromVersion(it) == pkg.id.version
}
val pkgRelease = pkgData["releases"]?.let { pkgReleases ->
val pkgVersion = pkgReleases.fieldNames().asSequence().find {
stripLeadingZerosFromVersion(it) == pkg.id.version
}

val pkgReleases = pkgData["releases"][pkgVersion] as? ArrayNode
pkgReleases[pkgVersion]
} as? ArrayNode

// Amend package information with more details.
Package(
id = pkg.id,
declaredLicenses = getDeclaredLicenses(pkgInfo),
description = pkgDescription,
homepageUrl = pkgHomepage,
binaryArtifact = if (pkgReleases != null) {
getBinaryArtifact(pkg, pkgReleases)
binaryArtifact = if (pkgRelease != null) {
getBinaryArtifact(pkg, pkgRelease)
} else {
pkg.binaryArtifact
},
sourceArtifact = if (pkgReleases != null) {
getSourceArtifact(pkgReleases)
sourceArtifact = if (pkgRelease != null) {
getSourceArtifact(pkgRelease)
} else {
pkg.sourceArtifact
},
vcs = pkg.vcs,
vcsProcessed = processPackageVcs(pkg.vcs, pkgHomepage)
)
} catch (e: NullPointerException) {
e.showStackTrace()

} ?: run {
log.warn {
"Unable to parse PyPI meta-data for package '${pkg.id.toCoordinates()}': ${e.message}"
"PyPI meta-data for package '${pkg.id.toCoordinates()}' does not provide any information."
}

// Fall back to returning the original package data.
Expand Down

0 comments on commit 3bd9491

Please sign in to comment.