-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Fix S2095 resource leaks and wrap HttpClient for AutoCloseable compatibility #24358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b263894
32c5573
d2b42a9
d26ec73
e53cb54
835a07b
f48351b
c1eff91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,8 @@ public Processor createProcessor() throws Exception { | |
| return createAggregator(); | ||
| } | ||
|
|
||
| // ExecutorService lifecycle is managed by AggregateProcessor via shutdownThreadPool flag | ||
| @SuppressWarnings("java:S2095") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This If SonarCloud is not recognizing the statement-level annotation, that would justify this change — could you confirm?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Claude Code on behalf of Guillaume Nodet Yes — SonarCloud is still flagging this file despite the statement-level Confirmed via API: Moving to method-level is the only approach SonarCloud recognizes for this pattern. We acknowledge it broadens the scope, but given that this method only creates one |
||
| protected AggregateProcessor createAggregator() throws Exception { | ||
| Processor childProcessor = this.createChildProcessor(true); | ||
|
|
||
|
|
@@ -76,8 +78,6 @@ protected AggregateProcessor createAggregator() throws Exception { | |
|
|
||
| boolean parallel = parseBoolean(definition.getParallelProcessing(), false); | ||
| boolean shutdownThreadPool = willCreateNewThreadPool(definition, parallel); | ||
| // ExecutorService lifecycle is managed by AggregateProcessor via shutdownThreadPool flag | ||
| @SuppressWarnings("java:S2095") | ||
| ExecutorService threadPool = getConfiguredExecutorService("Aggregator", definition, parallel); | ||
| if (threadPool == null && !parallel) { | ||
| // executor service is mandatory for the Aggregator | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,8 @@ public ThreadsReifier(Route route, ProcessorDefinition<?> definition) { | |
| super(route, (ThreadsDefinition) definition); | ||
| } | ||
|
|
||
| // ExecutorService lifecycle is managed by ThreadsProcessor via shutdownThreadPool flag | ||
| @SuppressWarnings("java:S2095") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as AggregateReifier — this was narrowed to statement level in #22343 after explicit review feedback.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Claude Code on behalf of Guillaume Nodet Same situation — SonarCloud still flags |
||
| @Override | ||
| public Processor createProcessor() throws Exception { | ||
| // the threads name | ||
|
|
@@ -43,8 +45,6 @@ public Processor createProcessor() throws Exception { | |
| } | ||
| // prefer any explicit configured executor service | ||
| boolean shutdownThreadPool = willCreateNewThreadPool(definition, true); | ||
| // ExecutorService lifecycle is managed by ThreadsProcessor via shutdownThreadPool flag | ||
| @SuppressWarnings("java:S2095") | ||
| ExecutorService threadPool = getConfiguredExecutorService(name, definition, false); | ||
|
|
||
| // resolve what rejected policy to use | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.camel.test.infra.openai.mock; | ||
|
|
||
| import java.net.http.HttpClient; | ||
|
|
||
| /** | ||
| * Wrapper that makes {@link HttpClient} usable in try-with-resources. On Java 21+ HttpClient implements AutoCloseable | ||
| * natively; the instanceof check future-proofs us for when the minimum JDK is raised. | ||
| */ | ||
| final class CloseableHttpClient implements AutoCloseable { | ||
| final HttpClient httpClient = HttpClient.newHttpClient(); | ||
|
|
||
| @Override | ||
| public void close() throws Exception { | ||
| if (httpClient instanceof AutoCloseable closeable) { | ||
| closeable.close(); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
// NOSONARinline comment was the accepted approach from PR #22343 review. Replacing it with method-level@SuppressWarningswidens the suppression scope. Same question: is SonarCloud not picking up the// NOSONAR?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude Code on behalf of Guillaume Nodet
Confirmed — SonarCloud still flags
SalesforceComponent.java:968despite the// NOSONARon line 967. The NOSONAR comment is on the constructor call line, but SonarCloud flags the next line (the argument). Method-level@SuppressWarningsis the fallback that SonarCloud actually respects for this pattern.