Fix Eclipse nullness errors 81/109181/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 6 Dec 2023 21:07:59 +0000 (22:07 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 6 Dec 2023 21:09:55 +0000 (22:09 +0100)
We have two error-level warnings reported for instantiated GeneratorTask
list. Fix them by annotating the result of instantiateGenerators().

While we are here, also clean up the method a bit and return an
ImmutableList instead.

Change-Id: Ic373c34671877c1cf5ce685ed38e55ef3579fc34
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java

index 1ed6f6888f8bb95879c87b7ea933d9755b35bfef..eae80170c5ffe158563db4fe016eb38cce333d0e 100644 (file)
@@ -347,17 +347,17 @@ class YangToSourcesProcessor {
         }
     }
 
-    private List<GeneratorTask> instantiateGenerators() throws MojoExecutionException {
+    private ImmutableList<@NonNull GeneratorTask> instantiateGenerators() throws MojoExecutionException {
         // Search for available FileGenerator implementations
-        final Map<String, FileGeneratorFactory> factories = Maps.uniqueIndex(
+        final var factories = Maps.uniqueIndex(
             ServiceLoader.load(FileGeneratorFactory.class), FileGeneratorFactory::getIdentifier);
 
         // FIXME: iterate over fileGeneratorArg instances (configuration), not factories (environment)
         // Assign instantiate FileGenerators with appropriate configuration
-        final var generators = new ArrayList<GeneratorTask>(factories.size());
-        for (Entry<String, FileGeneratorFactory> entry : factories.entrySet()) {
-            final String id = entry.getKey();
-            FileGeneratorArg arg = fileGeneratorArgs.get(id);
+        final var builder = ImmutableList.<@NonNull GeneratorTask>builderWithExpectedSize(factories.size());
+        for (var entry : factories.entrySet()) {
+            final var id = entry.getKey();
+            var arg = fileGeneratorArgs.get(id);
             if (arg == null) {
                 LOG.debug("{} No configuration for {}, using empty", LOG_PREFIX, id);
                 arg = new FileGeneratorArg(id);
@@ -369,7 +369,7 @@ class YangToSourcesProcessor {
             } catch (FileGeneratorException e) {
                 throw new MojoExecutionException("File generator " + id + " failed", e);
             }
-            generators.add(task);
+            builder.add(task);
             LOG.info("{} Code generator {} instantiated", LOG_PREFIX, id);
         }
 
@@ -382,7 +382,7 @@ class YangToSourcesProcessor {
             }
         );
 
-        return generators;
+        return builder.build();
     }
 
     @SuppressWarnings("checkstyle:illegalCatch")