From adf579c48890d956322c8087df23e054c8d5d8d8 Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Wed, 28 Jun 2023 20:48:31 +0900 Subject: [PATCH] =?UTF-8?q?[DROOLS-7484]=20ClassNotFoundException=20occurs?= =?UTF-8?q?=20when=20launching=20business-a=E2=80=A6=20(#5347)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [DROOLS-7484] ClassNotFoundException occurs when launching business-application by mvn spring-boot:run * - add null check --- .../java/org/kie/scanner/KieInJarModuleMetaDataImpl.java | 6 +++++- .../test/java/org/kie/scanner/KieModuleMetaDataTest.java | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/kie-ci/src/main/java/org/kie/scanner/KieInJarModuleMetaDataImpl.java b/kie-ci/src/main/java/org/kie/scanner/KieInJarModuleMetaDataImpl.java index e76912496e1..df06685be50 100644 --- a/kie-ci/src/main/java/org/kie/scanner/KieInJarModuleMetaDataImpl.java +++ b/kie-ci/src/main/java/org/kie/scanner/KieInJarModuleMetaDataImpl.java @@ -136,7 +136,11 @@ private Class getClass(String name) throws ClassNotFoundException { private byte[] loadClassData(String name) throws IOException { for (URL url : urls) { - URL tryUrl = new URL(url.toString() + "!/" + name); + if (url == null) { + continue; + } + String prefix = "file".equals(url.getProtocol()) ? "jar:" : ""; + URL tryUrl = new URL(prefix + url.toString() + "!/" + name); try (InputStream stream = tryUrl.openStream()) { if (stream == null) { continue; diff --git a/kie-ci/src/test/java/org/kie/scanner/KieModuleMetaDataTest.java b/kie-ci/src/test/java/org/kie/scanner/KieModuleMetaDataTest.java index 024913c918e..383380586b2 100644 --- a/kie-ci/src/test/java/org/kie/scanner/KieModuleMetaDataTest.java +++ b/kie-ci/src/test/java/org/kie/scanner/KieModuleMetaDataTest.java @@ -375,4 +375,11 @@ public void testKieMavenPluginEmptyProject() { } } + @Test + public void loadClassInJarKieModuleMetaData() { + ReleaseId releaseId = KieServices.Factory.get().newReleaseId("org.drools", "knowledge-api", "5.5.0.Final"); + KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newInJarKieModuleMetaData(releaseId, DependencyFilter.COMPILE_FILTER); + Class sessionClockClass = kieModuleMetaData.getClass("org.drools.time", "SessionClock"); + assertThat(sessionClockClass).isNotNull(); + } }