This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit 057d8f8bc0010551a1e4c0e4dc05546063374084
Author: Alex Heneveld <a...@cloudsoft.io>
AuthorDate: Mon Apr 1 16:19:37 2024 +0100

    allow from system if possible where bundle not known
    
    for use if switching to a pojo environment
---
 .../main/java/org/apache/brooklyn/util/core/ClassLoaderUtils.java | 6 +++++-
 .../java/org/apache/brooklyn/util/core/ClassLoaderUtilsTest.java  | 8 ++++----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git 
a/core/src/main/java/org/apache/brooklyn/util/core/ClassLoaderUtils.java 
b/core/src/main/java/org/apache/brooklyn/util/core/ClassLoaderUtils.java
index fc7e9bffe2..ce127c90bd 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/ClassLoaderUtils.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/ClassLoaderUtils.java
@@ -380,7 +380,11 @@ public class ClassLoaderUtils {
                             .reduce((v1, v2) -> v2));
                 }
                 if (bundle.isAbsent()) {
-                    throw new IllegalStateException("Bundle " + 
toBundleString(symbolicName, version)+ " not found to load.");
+                    // fall back to loading from system classpath, if running 
as pojo
+                    Maybe<T> result = dispatcher.tryLoadFrom(classLoader, 
name);
+                    if (result.isAbsent()) {
+                        throw new IllegalStateException("Bundle " + 
toBundleString(symbolicName, version) + " not found to load.");
+                    }
                 }
             }
             return dispatcher.tryLoadFrom(bundle.get(), name);
diff --git 
a/core/src/test/java/org/apache/brooklyn/util/core/ClassLoaderUtilsTest.java 
b/core/src/test/java/org/apache/brooklyn/util/core/ClassLoaderUtilsTest.java
index efa0aea290..7b6df6d797 100644
--- a/core/src/test/java/org/apache/brooklyn/util/core/ClassLoaderUtilsTest.java
+++ b/core/src/test/java/org/apache/brooklyn/util/core/ClassLoaderUtilsTest.java
@@ -308,23 +308,23 @@ public class ClassLoaderUtilsTest {
             new ClassLoaderUtils(this, mgmt).loadClass(
                     "org.apache.brooklyn.api",
                     "100.100.100-alpha-version_wth.tags",
-                    Entity.class.getName());
+                    "org.apache.brooklyn.NonExistentClass");  // actual 
classes may be found on the classpath
             Asserts.shouldHaveFailedPreviously();
         } catch (Exception e) {
             IllegalStateException nested = 
Exceptions.getFirstThrowableOfType(e, IllegalStateException.class);
             assertNotNull(nested);
-            Asserts.expectedFailureContains(nested, "not found to load");
+            Asserts.expectedFailureContains(nested, "not found to load", 
"org.apache.brooklyn.api", "100.100.100");
         }
         try {
             new ClassLoaderUtils(this, mgmt).loadClass(
                     "org.apache.brooklyn.api",
                     "100.100.100-SNAPSHOT",
-                    Entity.class.getName());
+                    "org.apache.brooklyn.NonExistentClass");  // actual 
classes may be found on the classpath
             Asserts.shouldHaveFailedPreviously();
         } catch (Exception e) {
             IllegalStateException nested = 
Exceptions.getFirstThrowableOfType(e, IllegalStateException.class);
             assertNotNull(nested);
-            Asserts.expectedFailureContains(nested, "not found to load");
+            Asserts.expectedFailureContains(nested, "not found to load", 
"org.apache.brooklyn.api", "100.100.100");
         }
     }
 

Reply via email to