From 18bd8ae17056253917b5031be3788b0d8d0c8087 Mon Sep 17 00:00:00 2001 From: Tim Yates Date: Fri, 9 Feb 2024 14:40:08 +0000 Subject: [PATCH] fix: mn create fails since 4.3.0 (#2319) In 4.3.0 when we added chatbot creation, we abstracted the builder commands away. At one point, we combine application-type features and user specified features into a single set. The issue here is that the set in the case of the create command was unmodifiable. This then failed with the esoteric 'Error null' message. This PR takes the features from the application type, and loads them into a HashSet prior to doing any manipulation. I did it this way as it's hard to test this area of the functionality, and it will prevent us having a similar issue if we add further commands Closes #2318 --- .../micronaut/starter/cli/command/BuilderCommand.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/starter-cli/src/main/java/io/micronaut/starter/cli/command/BuilderCommand.java b/starter-cli/src/main/java/io/micronaut/starter/cli/command/BuilderCommand.java index 2f7dca00813..eab6e75127c 100644 --- a/starter-cli/src/main/java/io/micronaut/starter/cli/command/BuilderCommand.java +++ b/starter-cli/src/main/java/io/micronaut/starter/cli/command/BuilderCommand.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2023 original authors + * Copyright 2017-2024 original authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,12 +44,12 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.Callable; import java.util.function.Function; import java.util.function.Supplier; -import java.util.stream.Collectors; import static picocli.CommandLine.Help.Ansi.AUTO; @@ -83,7 +83,8 @@ public Integer call() throws Exception { .parser(new DefaultParser()) .build(); GenerateOptions options = createGenerateOptions(reader); - Set selectedFeatures = options.getFeatures(); + // options.getFeatures() may be an unmodifiable set, so unpack it into a modifiable set + Set selectedFeatures = new HashSet<>(options.getFeatures()); selectedFeatures.addAll(getFeatures(options.getApplicationType(), terminal, features)); Project project = getProject(reader); try (OutputHandler outputHandler = new FileSystemOutputHandler(project, false, this)) { @@ -106,7 +107,7 @@ public Integer call() throws Exception { protected List getFeatures(ApplicationType applicationType, Terminal terminal, List features) { AvailableFeatures availableFeatures = new BaseAvailableFeatures(features, applicationType); - List featureNames = availableFeatures.getFeatures().map(Feature::getName).collect(Collectors.toList()); + List featureNames = availableFeatures.getFeatures().map(Feature::getName).toList(); LineReader featuresReader = LineReaderBuilder.builder() .terminal(terminal) .completer(new StringsCompleter(featureNames)) @@ -123,7 +124,7 @@ protected List getFeatures(ApplicationType applicationType, Terminal ter List selectedFeatures = Arrays.asList(featuresLine.split(" ")); List invalidFeatures = new ArrayList<>(); for (String name: selectedFeatures) { - if (!availableFeatures.findFeature(name).isPresent()) { + if (availableFeatures.findFeature(name).isEmpty()) { invalidFeatures.add(name); } }