Skip to content

Commit 77ec25d

Browse files
committed
Fixed NPE when setting Types field in core-libraries
The core libraries may come from platforms installed inside the "sketchbook/hardware" directory. Those platforms are not indexed and doesn't have a category field to propagate in the core-libraries.
1 parent 3bce820 commit 77ec25d

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import java.util.ArrayList;
5353
import java.util.Collections;
5454
import java.util.List;
55+
import java.util.Optional;
5556

5657
import static processing.app.I18n.tr;
5758

@@ -151,8 +152,11 @@ public void rescanLibraries() {
151152
.filter(l -> l.getTypes().contains("Contributed")) //
152153
.filter(l -> l.getLocation() == Location.CORE || l.getLocation() == Location.REFERENCED_CORE) //
153154
.forEach(l -> {
154-
ContributedPlatform platform = BaseNoGui.indexer.getPlatformByFolder(l.getInstalledFolder());
155-
l.setTypes(Collections.singletonList(platform.getCategory()));
155+
File libFolder = l.getInstalledFolder();
156+
Optional<ContributedPlatform> platform = BaseNoGui.indexer.getPlatformByFolder(libFolder);
157+
if (platform.isPresent()) {
158+
l.setTypes(Collections.singletonList(platform.get().getCategory()));
159+
}
156160
});
157161
}
158162

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -461,13 +461,11 @@ private List<ContributedPlatform> getInstalledPlatforms() {
461461
return index.getInstalledPlatforms();
462462
}
463463

464-
public ContributedPlatform getPlatformByFolder(final File folder) {
465-
Optional<ContributedPlatform> platformOptional = getInstalledPlatforms().stream().filter(contributedPlatform -> {
464+
public Optional<ContributedPlatform> getPlatformByFolder(final File folder) {
465+
return getInstalledPlatforms().stream().filter(contributedPlatform -> {
466466
assert contributedPlatform.getInstalledFolder() != null;
467467
return FileUtils.isSubDirectory(contributedPlatform.getInstalledFolder(), folder);
468468
}).findFirst();
469-
470-
return platformOptional.orElse(null);
471469
}
472470

473471
public ContributedPlatform getContributedPlaform(TargetPlatform targetPlatform) {

0 commit comments

Comments
 (0)