58
58
import org .eclipse .lsp4j .services .WorkspaceService ;
59
59
60
60
import com .google .gson .JsonPrimitive ;
61
+ import com .google .gson .JsonElement ;
61
62
62
63
import common .ConsCell ;
63
64
import common .DecoratedNode ;
@@ -248,6 +249,19 @@ private void setParserFactory(Supplier<SilverCopperParser<NRoot>> parserFactory)
248
249
parserFn = new CopperParserNodeFactory (parserFactory );
249
250
}
250
251
252
+ // This method is meant to deal with jsonNull, an element that is technically
253
+ // not null according to java but is a null element passed through json.
254
+ // It gets a string from a list containing json elements and returns "" if the element
255
+ // is null.
256
+ private String getJsonStringFromConfigList (List <Object > configs , int index ){
257
+ Object itemGet = configs .get (index );
258
+ if (itemGet != null && !((JsonElement )itemGet ).isJsonNull ()) {
259
+ return ((JsonPrimitive )itemGet ).getAsString ();
260
+ } else {
261
+ return "" ;
262
+ }
263
+ }
264
+
251
265
private CompletableFuture <Void > reloadParser () {
252
266
ConfigurationItem compilerJarConfigItem = new ConfigurationItem ();
253
267
compilerJarConfigItem .setSection ("silver.compilerJar" );
@@ -258,8 +272,8 @@ private CompletableFuture<Void> reloadParser() {
258
272
return client .configuration (configParams ).thenAccept ((configs ) -> {
259
273
String oldParserJar = compilerJar ;
260
274
String oldParserName = parserName ;
261
- compilerJar = (( JsonPrimitive ) configs . get ( 0 )). getAsString ( );
262
- parserName = (( JsonPrimitive ) configs . get ( 1 )). getAsString ( );
275
+ compilerJar = this . getJsonStringFromConfigList ( configs , 0 );
276
+ parserName = this . getJsonStringFromConfigList ( configs , 1 );
263
277
if (compilerJar .isEmpty () || parserName .isEmpty ()) {
264
278
if (!compilerJar .equals (oldParserJar ) || !parserName .equals (oldParserName )) {
265
279
setParserFactory (Parser_silver_compiler_composed_Default_svParse ::new );
@@ -375,7 +389,10 @@ private void doBuild(Map<String, Integer> buildVersions) {
375
389
ConfigurationParams configParams = new ConfigurationParams (List .of (enableMWDAConfigItem ));
376
390
boolean newEnableMWDA = enableMWDA ;
377
391
try {
378
- newEnableMWDA = ((JsonPrimitive )client .configuration (configParams ).get ().get (0 )).getAsBoolean ();
392
+ Object configMWDAGet = client .configuration (configParams ).get ().get (0 );
393
+ if (configMWDAGet != null && !((JsonElement )configMWDAGet ).isJsonNull ()) {
394
+ newEnableMWDA = ((JsonPrimitive )configMWDAGet ).getAsBoolean ();
395
+ }
379
396
} catch (InterruptedException | ExecutionException e ) {
380
397
// Ignore, getting the settings sometimes fails when a build is triggered during initialization
381
398
}
0 commit comments