gnodet-bot commented on code in PR #29464:
URL: https://github.com/apache/camel/pull/29464#discussion_r4512787657
##########
components/camel-chaos/src/main/java/org/apache/camel/component/chaos/ChaosAdvisor.java:
##########
@@ -98,12 +100,29 @@ enum Kind {
* @param rank higher is tried first
* @param routes the routes a rule of its kind tries it in: the route, and
the other routes of a dead letter channel
* they share, which is suggested once
+ * @param with the other rules to add with the rule, for two faults at
once (CAMEL-26772); empty for one fault
*/
record Suggestion(String route, Kind kind, String recipe, String title,
String rule, String why, int rank,
- List<String> routes) {
+ List<String> routes, List<String> with) {
Suggestion(String route, Kind kind, String recipe, String title,
String rule, String why, int rank) {
- this(route, kind, recipe, title, rule, why, rank, List.of(route));
+ this(route, kind, recipe, title, rule, why, rank, List.of(route),
List.of());
+ }
+
+ Suggestion(String route, Kind kind, String recipe, String title,
String rule, String why, int rank,
+ List<String> routes) {
+ this(route, kind, recipe, title, rule, why, rank, routes,
List.of());
+ }
+
+ /** The rules to add: the rule, and the rules to add with it. */
+ List<String> rules() {
+ if (with.isEmpty()) {
+ return List.of(rule);
+ }
+ List<String> answer = new ArrayList<>();
+ answer.add(rule);
+ answer.addAll(with);
+ return answer;
Review Comment:
💡 **Suggestion:** `rules()` returns an immutable `List.of` for the
single-fault path but a mutable `ArrayList` for the combined path —
inconsistent mutability contract. No caller currently mutates the result, but
it's a latent hazard. Use `List.copyOf` to unify both paths:
```suggestion
List<String> rules() {
if (with.isEmpty()) {
return List.of(rule);
}
List<String> answer = new ArrayList<>();
answer.add(rule);
answer.addAll(with);
return List.copyOf(answer);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]