Skip to content

Commit 576b933

Browse files
authored
Merge pull request #358 from spyrkob/GAL-370_release_cl_error
[GAL-370] Move unused classloader error to debug level
2 parents 1a0e916 + 2421706 commit 576b933

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

api/src/main/java/org/jboss/galleon/api/GalleonBuilder.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 Red Hat, Inc. and/or its affiliates
2+
* Copyright 2016-2025 Red Hat, Inc. and/or its affiliates
33
* and other contributors as indicated by the @author tags.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,6 +28,8 @@
2828
import java.util.Collections;
2929
import java.util.HashMap;
3030
import java.util.Map;
31+
32+
import org.jboss.galleon.MessageWriter;
3133
import org.jboss.galleon.ProvisioningException;
3234
import org.jboss.galleon.api.config.GalleonFeaturePackConfig;
3335
import org.jboss.galleon.api.config.GalleonProvisioningConfig;
@@ -223,13 +225,15 @@ private static Path getTmpDirectory() throws ProvisioningException {
223225
}
224226
}
225227

226-
static synchronized void releaseUsage(String version) throws ProvisioningException {
228+
static synchronized void releaseUsage(String version, MessageWriter log) throws ProvisioningException {
227229
ClassLoaderUsage usage = classLoaders.get(version);
228230
if (usage == null) {
229-
throw new ProvisioningException("Releasing usage of core " + version + " although no usage");
231+
log.verbose("Releasing usage of core " + version + " although no usage");
232+
return;
230233
}
231234
if (usage.num <= 0) {
232-
throw new ProvisioningException("Releasing usage of core " + version + " although all usages released");
235+
log.verbose("Releasing usage of core " + version + " although all usages released");
236+
return;
233237
}
234238
usage.num -= 1;
235239
if (usage.num == 0) {

api/src/main/java/org/jboss/galleon/api/ProvisioningImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 Red Hat, Inc. and/or its affiliates
2+
* Copyright 2016-2025 Red Hat, Inc. and/or its affiliates
33
* and other contributors as indicated by the @author tags.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -166,7 +166,7 @@ public void close() {
166166
}
167167
} finally {
168168
try {
169-
GalleonBuilder.releaseUsage(coreVersion);
169+
GalleonBuilder.releaseUsage(coreVersion, this.log);
170170
} catch (ProvisioningException ex) {
171171
System.err.println("Error releasing classloader " + ex.getLocalizedMessage());
172172
}

api/src/test/java/org/jboss/galleon/api/GalleonBuilderTestCase.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 Red Hat, Inc. and/or its affiliates
2+
* Copyright 2016-2025 Red Hat, Inc. and/or its affiliates
33
* and other contributors as indicated by the @author tags.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,11 @@
1717
package org.jboss.galleon.api;
1818

1919
import java.net.URLClassLoader;
20+
import java.util.concurrent.atomic.AtomicReference;
21+
2022
import org.jboss.galleon.CoreVersion;
23+
import org.jboss.galleon.DefaultMessageWriter;
24+
import org.jboss.galleon.MessageWriter;
2125
import org.jboss.galleon.ProvisioningException;
2226
import org.jboss.galleon.api.test.FeaturePackRepoTestBase;
2327
import org.jboss.galleon.creator.FeaturePackCreator;
@@ -35,6 +39,7 @@
3539
public class GalleonBuilderTestCase extends FeaturePackRepoTestBase {
3640

3741
private static final FeaturePackLocation.FPID FP1_100_GAV = LegacyGalleon1Universe.newFPID("org.jboss.pm.test:fp1", "1", "1.0.0.Final");
42+
private final MessageWriter log = new DefaultMessageWriter();
3843

3944
@Override
4045
protected void doBefore() throws Exception {
@@ -50,12 +55,18 @@ public void test() throws Exception {
5055
GalleonBuilder builder = new GalleonBuilder();
5156
builder.addArtifactResolver(repo);
5257
assertEquals(GalleonBuilder.getClassLoaders().size(), 0);
53-
try {
54-
GalleonBuilder.releaseUsage(CoreVersion.getVersion());
55-
throw new Exception("Should have failed");
56-
} catch (ProvisioningException ex) {
57-
// Ok should have failed.
58-
}
58+
59+
// verify that releasing unused CL is logged
60+
AtomicReference<String> msg = new AtomicReference<>(null);
61+
GalleonBuilder.releaseUsage(CoreVersion.getVersion(), new DefaultMessageWriter() {
62+
@Override
63+
public void verbose(CharSequence message) {
64+
msg.set(message.toString());
65+
}
66+
});
67+
assertEquals("Releasing usage of core " + CoreVersion.getVersion() + " although no usage",
68+
msg.get());
69+
5970
URLClassLoader l1 = GalleonBuilder.getCallerClassLoader(APIVersion.getVersion(), null);
6071
assertEquals(GalleonBuilder.getClassLoaders().size(), 1);
6172
URLClassLoader l2 = GalleonBuilder.getCallerClassLoader(APIVersion.getVersion(), null);
@@ -65,9 +76,9 @@ public void test() throws Exception {
6576
assertEquals(l1, l3);
6677
assertEquals(GalleonBuilder.getClassLoaders().size(), 1);
6778
// Release all usages.
68-
GalleonBuilder.releaseUsage(CoreVersion.getVersion());
69-
GalleonBuilder.releaseUsage(CoreVersion.getVersion());
70-
GalleonBuilder.releaseUsage(CoreVersion.getVersion());
79+
GalleonBuilder.releaseUsage(CoreVersion.getVersion(), this.log);
80+
GalleonBuilder.releaseUsage(CoreVersion.getVersion(), this.log);
81+
GalleonBuilder.releaseUsage(CoreVersion.getVersion(), this.log);
7182
assertEquals(GalleonBuilder.getClassLoaders().size(), 0);
7283
URLClassLoader l4 = GalleonBuilder.getCallerClassLoader(CoreVersion.getVersion(), null);
7384
assertNotEquals(l1, l4);
@@ -79,9 +90,9 @@ public void test() throws Exception {
7990
assertEquals(loader, loader2);
8091
assertEquals(GalleonBuilder.getClassLoaders().size(), 1);
8192
// Release all usages
82-
GalleonBuilder.releaseUsage(CoreVersion.getVersion());
83-
GalleonBuilder.releaseUsage(CoreVersion.getVersion());
84-
GalleonBuilder.releaseUsage(CoreVersion.getVersion());
93+
GalleonBuilder.releaseUsage(CoreVersion.getVersion(), this.log);
94+
GalleonBuilder.releaseUsage(CoreVersion.getVersion(), this.log);
95+
GalleonBuilder.releaseUsage(CoreVersion.getVersion(), this.log);
8596
try {
8697
builder.getCoreClassLoader("foo");
8798
throw new Exception();

0 commit comments

Comments
 (0)