Skip to content

Commit

Permalink
Fix null cases
Browse files Browse the repository at this point in the history
  • Loading branch information
gschneider-r7 committed Jun 20, 2019
1 parent dc3180b commit 8316a41
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ private OperatingSystem parseOsRelease(InputStream input, String architecture) t
try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) {
String line = null;
String id = null;
String product = null;
String product = OS_FAMILY;
String description = null;
String version = null;
String version = "";
while ((line = reader.readLine()) != null) {
Matcher matcher = PATTERN.matcher(line);
if (matcher.matches()) {
String name = matcher.group("name");
String value = matcher.group("value");
switch (name) {
case "ID":
id = value.replaceAll("\"", "");
id = value.replaceAll("\"", "").toLowerCase();
break;
case "NAME":
case "DISTRIB_ID":
Expand All @@ -94,10 +94,10 @@ private OperatingSystem parseOsRelease(InputStream input, String architecture) t
}

String vendor = OS_ID_TO_VENDOR.get(id);
if (!vendor.equals("VMWare"))
if (!"VMWare".equals(vendor))
product = OS_FAMILY;

return fingerprintOperatingSystem(vendor, product, version, architecture);
return fingerprintOperatingSystem(vendor != null ? vendor : OS_FAMILY, product, version, architecture);
}
}

Expand All @@ -119,9 +119,9 @@ private OperatingSystem parseRhelFamilyRelease(InputStream input, String archite
private OperatingSystem parseAlpineRelease(InputStream input, String architecture) throws IOException {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) {
String line = null;
String version = null;
String version = "";
while ((line = reader.readLine()) != null) {
if (version == null && line.matches("(?:\\d+(?:\\.)?)+"))
if (version.isEmpty() && line.matches("(?:\\d+(?:\\.)?)+"))
version = line;
}

Expand All @@ -146,7 +146,7 @@ private OperatingSystem parsePhotonRelease(InputStream input, String architectur
}

private OperatingSystem fingerprintOperatingSystem(String vendor, String product, String version, String architecture) {
if (vendor.equals("VMWare"))
if ("VMWare".equals(vendor))
product = "Photon Linux";

return new OperatingSystem(vendor, OS_FAMILY, product, architecture, version, vendor + " " + product + " " + version);
Expand Down

0 comments on commit 8316a41

Please sign in to comment.