Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,16 @@ public BuildResult run() throws Exception {
long start = System.nanoTime();
log.debug("Beginning Quarkus augmentation");
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
QuarkusBuildCloseablesBuildItem buildCloseables = new QuarkusBuildCloseablesBuildItem();
try {
try (QuarkusBuildCloseablesBuildItem buildCloseables = new QuarkusBuildCloseablesBuildItem()) {
Thread.currentThread().setContextClassLoader(deploymentClassLoader);

final BuildChainBuilder chainBuilder = BuildChain.builder();
chainBuilder.setClassLoader(deploymentClassLoader);

ExtensionLoader.loadStepsFrom(deploymentClassLoader,
buildSystemProperties == null ? new Properties() : buildSystemProperties,
runtimeProperties == null ? new Properties() : runtimeProperties,
effectiveModel, launchMode, devModeType)
buildSystemProperties == null ? new Properties() : buildSystemProperties,
runtimeProperties == null ? new Properties() : runtimeProperties,
effectiveModel, launchMode, devModeType)
.accept(chainBuilder);

Thread.currentThread().setContextClassLoader(classLoader);
Expand Down Expand Up @@ -184,7 +183,6 @@ public BuildResult run() throws Exception {

}
Thread.currentThread().setContextClassLoader(originalClassLoader);
buildCloseables.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ public void collectInput() throws IOException {
return;
}
final TerminalConnection connection = new TerminalConnection();
connection.setSignalHandler(interruptionSignalHandler());
try {
try (connection) {
connection.setSignalHandler(interruptionSignalHandler());
read(connection, ReadlineBuilder.builder().enableHistory(false).build(), prompts.iterator());
connection.openBlocking();
} finally {
connection.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,11 @@ private SocketUtil() {
}

static int findAvailablePort() {
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(0);
try (ServerSocket serverSocket = new ServerSocket(0)) {
return serverSocket.getLocalPort();
} catch (Exception e) {
// return a default port
return 25347;
} finally {
if (serverSocket != null) {
try {
serverSocket.close();
} catch (IOException e) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this catch is missing.

}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,13 @@ public void accept(Object o, Throwable throwable) {
});
} else {
final Context currentSpanContext = instrumenter.start(parentContext, methodRequest);
final Scope currentScope = currentSpanContext.makeCurrent();
try {
try (Scope currentScope = currentSpanContext.makeCurrent()) {
Object result = invocationContext.proceed();
instrumenter.end(currentSpanContext, methodRequest, null, null);
return result;
} catch (Throwable t) {
instrumenter.end(currentSpanContext, methodRequest, null, t);
throw t;
} finally {
if (currentScope != null) {
currentScope.close();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is save, as equal.

}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,18 @@ private static io.vertx.core.Context getVertxContext(final ClientRequestContext

@Override
public void filter(final ClientRequestContext request, final ClientResponseContext response) {
Scope scope = (Scope) request.getProperty(REST_CLIENT_OTEL_SPAN_CLIENT_SCOPE);
if (scope == null) {
return;
}

Context spanContext = (Context) request.getProperty(REST_CLIENT_OTEL_SPAN_CLIENT_CONTEXT);
try {
try (Scope scope = (Scope) request.getProperty(REST_CLIENT_OTEL_SPAN_CLIENT_SCOPE)) {
if (scope == null) {
return;
}
Context spanContext = (Context) request.getProperty(REST_CLIENT_OTEL_SPAN_CLIENT_CONTEXT);
String pathTemplate = (String) request.getProperty(URL_PATH_TEMPLATE_KEY);
if (pathTemplate != null && !pathTemplate.isEmpty()) {
Span.fromContext(spanContext)
.updateName(request.getMethod() + " " + pathTemplate);
}
instrumenter.end(spanContext, request, response, null);
} finally {
scope.close();

request.removeProperty(REST_CLIENT_OTEL_SPAN_CLIENT_CONTEXT);
request.removeProperty(REST_CLIENT_OTEL_SPAN_CLIENT_PARENT_CONTEXT);
request.removeProperty(REST_CLIENT_OTEL_SPAN_CLIENT_SCOPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ static Object getObjectFromInput(InputStream binaryInput) throws ClassNotFoundEx
}
// use an instance of the QuarkusObjectInputStream class instead of the ObjectInputStream when deserializing
// to workaround a CNFE in test and dev mode.
ObjectInputStream in = new QuarkusObjectInputStream(binaryInput);
try {
try (ObjectInputStream in = new QuarkusObjectInputStream(binaryInput)) {
return in.readObject();
} finally {
in.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,11 @@ private String generateURL() {
public void testClientQuality() throws Exception {
Invocation.Builder request = client.target(generateURL()).path("echo").request("application/x;q=0.7",
"application/y;q=0.9");
Response response = request.get();
try {
try (Response response = request.get()) {
Assertions.assertEquals(Status.OK.getStatusCode(), response.getStatus());
MediaType mediaType = response.getMediaType();
Assertions.assertEquals(mediaType.getType(), "application");
Assertions.assertEquals(mediaType.getSubtype(), "y");
} finally {
response.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,11 @@ private String generateURL() {
@DisplayName("Test Server Quality")
public void testServerQuality() throws Exception {
Invocation.Builder request = client.target(generateURL()).path("foo/echo").request("application/x;", "text/y");
Response response = request.get();
try {
try (Response response = request.get()) {
Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
MediaType mediaType = response.getMediaType();
Assertions.assertEquals("text", mediaType.getType());
Assertions.assertEquals("y", mediaType.getSubtype());
} finally {
response.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,8 @@ public void testRelativize() throws Exception {
}

private static void basicTest(String path, String testName) throws Exception {
Response response = client.target(PortProviderUtil.generateURL("/" + testName + path)).request().get();
try {
try (Response response = client.target(PortProviderUtil.generateURL("/" + testName + path)).request().get()) {
Assertions.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
} finally {
response.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public void testHttpRootPath() throws Exception {

LinkedBlockingDeque<String> message = new LinkedBlockingDeque<>();
LinkedBlockingDeque<String> pongMessages = new LinkedBlockingDeque<>();
Session session = ContainerProvider.getWebSocketContainer().connectToServer(new Endpoint() {

try (Session session = ContainerProvider.getWebSocketContainer().connectToServer(new Endpoint() {
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
session.addMessageHandler(new MessageHandler.Whole<String>() {
Expand All @@ -68,14 +69,10 @@ public void onMessage(PongMessage s) {
throw new RuntimeException(e);
}
}
}, ClientEndpointConfig.Builder.create().build(), echoUri);

try {
}, ClientEndpointConfig.Builder.create().build(), echoUri)) {
Assertions.assertEquals("hello", message.poll(20, TimeUnit.SECONDS));

Assertions.assertEquals("PING", pongMessages.poll(20, TimeUnit.SECONDS));
} finally {
session.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,15 @@ private static void doReaugment(Path appRoot) throws IOException, ClassNotFoundE
Files.newInputStream(appRoot.resolve(LIB_DEPLOYMENT_DEPLOYMENT_CLASS_PATH_DAT)))) {
List<String> paths = (List<String>) in.readObject();
//yuck, should use runner class loader
URLClassLoader loader = new URLClassLoader(paths.stream().map((s) -> {
try (URLClassLoader loader = new URLClassLoader(paths.stream().map((s) -> {
try {
return appRoot.resolve(s).toUri().toURL();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}).toArray(URL[]::new));
try {
}).toArray(URL[]::new))) {
loader.loadClass("io.quarkus.deployment.mutability.ReaugmentTask")
.getDeclaredMethod("main", Path.class).invoke(null, appRoot);
} finally {
loader.close();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@ public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotat

public void writeTo(Reader inputStream, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException {
try {
try (inputStream) {
int c;
while ((c = inputStream.read()) != -1) {
entityStream.write(c);
}
} finally {
try {
inputStream.close();
} catch (IOException e) {
// Drop the exception so we don't mask real IO errors
}
} catch (IOException e) {
// Drop the exception so we don't mask real IO errors
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,11 @@ private String generateURL() {
public void testClientQuality() throws Exception {
Invocation.Builder request = client.target(generateURL()).path("echo").request("application/x;q=0.7",
"application/y;q=0.9");
Response response = request.get();
try {
try (Response response = request.get()) {
Assertions.assertEquals(Status.OK.getStatusCode(), response.getStatus());
MediaType mediaType = response.getMediaType();
Assertions.assertEquals(mediaType.getType(), "application");
Assertions.assertEquals(mediaType.getSubtype(), "y");
} finally {
response.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,11 @@ private String generateURL() {
@DisplayName("Test Server Quality")
public void testServerQuality() throws Exception {
Invocation.Builder request = client.target(generateURL()).path("foo/echo").request("application/x;", "text/y");
Response response = request.get();
try {
try (Response response = request.get()) {
Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
MediaType mediaType = response.getMediaType();
Assertions.assertEquals("text", mediaType.getType());
Assertions.assertEquals("y", mediaType.getSubtype());
} finally {
response.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,8 @@ public void testResolve() throws Exception {
}

private static void basicTest(String path, String testName) throws Exception {
Response response = client.target(PortProviderUtil.generateURL("/" + testName + path)).request().get();
try {
try (Response response = client.target(PortProviderUtil.generateURL("/" + testName + path)).request().get()) {
Assertions.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
} finally {
response.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,12 @@ public void testInteractionWithAPIServer() {

@Test
public void testEcKeyIsSupported() throws Exception {
InputStream certInputStream = KubernetesClientTest.class.getResourceAsStream("/cert.pem");
InputStream keyInputStream = KubernetesClientTest.class.getResourceAsStream("/private-key.pem");

try {
try (InputStream certInputStream = KubernetesClientTest.class.getResourceAsStream("/cert.pem"); InputStream keyInputStream = KubernetesClientTest.class.getResourceAsStream("/private-key.pem")) {
KeyStore keyStore = CertUtils.createKeyStore(certInputStream, keyInputStream, "EC", "eckey".toCharArray(),
(String) null, "keystore".toCharArray());
Key key = keyStore.getKey("CN=Client,OU=Test,O=Test", "eckey".toCharArray());
assertTrue(key instanceof ECPrivateKey);
} finally {
certInputStream.close();
keyInputStream.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void setSse(final Sse sse) {
@Produces(MediaType.SERVER_SENT_EVENTS)
public void sendData(@Context SseEventSink sink) {
// send a stream of few events
try {
try (sink) {
for (int i = 0; i < 3; i++) {
final OutboundSseEvent.Builder builder = this.sse.newEventBuilder();
builder.id(String.valueOf(i)).mediaType(MediaType.TEXT_PLAIN_TYPE)
Expand All @@ -35,8 +35,6 @@ public void sendData(@Context SseEventSink sink) {

sink.send(builder.build());
}
} finally {
sink.close();
}
}

Expand All @@ -46,7 +44,7 @@ public void sendData(@Context SseEventSink sink) {
@SseElementType("text/html")
public void sendHtmlData(@Context SseEventSink sink) {
// send a stream of few events
try {
try (sink) {
for (int i = 0; i < 3; i++) {
final OutboundSseEvent.Builder builder = this.sse.newEventBuilder();
builder.id(String.valueOf(i)).mediaType(MediaType.TEXT_HTML_TYPE)
Expand All @@ -55,8 +53,6 @@ public void sendHtmlData(@Context SseEventSink sink) {

sink.send(builder.build());
}
} finally {
sink.close();
}
}

Expand All @@ -66,7 +62,7 @@ public void sendHtmlData(@Context SseEventSink sink) {
@Produces(MediaType.SERVER_SENT_EVENTS)
public void sendXmlData(@Context SseEventSink sink) {
// send a stream of few events
try {
try (sink) {
for (int i = 0; i < 3; i++) {
final OutboundSseEvent.Builder builder = this.sse.newEventBuilder();
builder.id(String.valueOf(i)).mediaType(MediaType.TEXT_XML_TYPE)
Expand All @@ -75,8 +71,6 @@ public void sendXmlData(@Context SseEventSink sink) {

sink.send(builder.build());
}
} finally {
sink.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,14 @@ public Response response() {
@Produces(MediaType.SERVER_SENT_EVENTS)
public void serverSentEvents(@Context SseEventSink sink) {
VanillaJavaImmutableData data = new VanillaJavaImmutableData("sse", "ssevalue");
try {
try (sink) {
OutboundSseEvent.Builder builder = sse.newEventBuilder();
builder.id(String.valueOf(1))
.mediaType(MediaType.APPLICATION_JSON_TYPE)
.data(data)
.name("stream of json data");

sink.send(builder.build());
} finally {
sink.close();
}
}

Expand Down
Loading
Loading