Skip to content

Commit b9a90f6

Browse files
author
Federico Fissore
committed
Invalid versions don't cause IDE to crash and exit any more. They are reported and contributions are considered missing version. Fixes #2926
1 parent 8020c0d commit b9a90f6

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

arduino-core/src/cc/arduino/contributions/VersionHelper.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@ public static Version valueOf(String ver) {
88
if (ver == null) {
99
return null;
1010
}
11-
String[] verParts = ver.split("\\.");
12-
if (verParts.length < 3) {
13-
if (verParts.length == 2) {
14-
return Version.forIntegers(Integer.valueOf(verParts[0]), Integer.valueOf(verParts[1]));
11+
try {
12+
String[] verParts = ver.split("\\.");
13+
if (verParts.length < 3) {
14+
if (verParts.length == 2) {
15+
return Version.forIntegers(Integer.valueOf(verParts[0]), Integer.valueOf(verParts[1]));
16+
} else {
17+
return Version.forIntegers(Integer.valueOf(verParts[0]));
18+
}
1519
} else {
16-
return Version.forIntegers(Integer.valueOf(verParts[0]));
20+
return Version.valueOf(ver);
1721
}
18-
} else {
19-
return Version.valueOf(ver);
22+
} catch (Exception e) {
23+
System.err.println("Invalid version found: " + ver);
24+
return null;
2025
}
2126
}
2227

arduino-core/src/cc/arduino/contributions/libraries/ContributedLibrary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public boolean equals(Object obj) {
141141
String thisVersion = getParsedVersion();
142142
String otherVersion = ((ContributedLibrary) obj).getParsedVersion();
143143

144-
boolean versionEquals = thisVersion == null || otherVersion == null || thisVersion.equals(otherVersion);
144+
boolean versionEquals = thisVersion == otherVersion || (thisVersion != null && otherVersion != null && thisVersion.equals(otherVersion));
145145

146146
String thisName = getName();
147147
String otherName = ((ContributedLibrary) obj).getName();

arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndex.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public boolean apply(ContributedLibrary contributedLibrary) {
4848
}
4949

5050
public ContributedLibrary find(String name, String version) {
51+
if (name == null || version == null) {
52+
return null;
53+
}
5154
for (ContributedLibrary lib : find(name)) {
5255
if (version.equals(lib.getParsedVersion())) {
5356
return lib;

arduino-core/src/cc/arduino/contributions/packages/ContributedPackage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public abstract class ContributedPackage {
4747
public abstract List<ContributedTool> getTools();
4848

4949
public ContributedPlatform findPlatform(String architecture, String version) {
50+
if (architecture == null || version == null) {
51+
return null;
52+
}
5053
for (ContributedPlatform platform : getPlatforms()) {
5154
if (platform.getArchitecture().equals(architecture) && version.equals(platform.getParsedVersion()))
5255
return platform;

0 commit comments

Comments
 (0)