diff --git a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java
index a1ca10929d9..35a53e906de 100644
--- a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java
+++ b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java
@@ -215,7 +215,7 @@ public void syncWithFilesystem() throws IOException {
   }
 
   private void syncBuiltInHardware() throws IOException {
-    if (index == null) {
+    if (index == null || builtInHardwareFolder == null) {
       return;
     }
     for (File folder : builtInHardwareFolder.listFiles(ONLY_DIRS)) {
diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java
index 920d0e0685d..37d4b33e9f0 100644
--- a/arduino-core/src/processing/app/BaseNoGui.java
+++ b/arduino-core/src/processing/app/BaseNoGui.java
@@ -676,7 +676,9 @@ static public void onBoardOrPortChange() {
     // Libraries located in the latest folders on the list can override
     // other libraries with the same name.
     librariesIndexer.setLibrariesFolders(librariesFolders);
-    librariesIndexer.setArchitecturePriority(getTargetPlatform().getId());
+    if (getTargetPlatform() != null) {
+      librariesIndexer.setArchitecturePriority(getTargetPlatform().getId());
+    }
     librariesIndexer.rescanLibraries();
 
     populateImportToLibraryTable();