[rules-dev] [JBRULES-3630] RFC - ClassPathResources within ChangeSet are loaded using wrong ClassLoader

Chris Rankin rankincj at googlemail.com
Mon Sep 24 07:14:46 EDT 2012


On Mon, Sep 24, 2012 at 10:06 AM, Mario Fusco <mario.fusco at gmail.com> wrote:
> I tried the reproduce your issue on the master branch with the very simple
> test case (practically identical to the one you reported on the jira ticket)
> that I am pasting below, but it works for me. I didn't try the same on the
> 5.1.1 though. Anyway can you please confirm that my test should be enough to
> reproduce your problem? Because, if so, I believe that, at least on the
> master, this bug should be already fixed.
>
> Thanks,
> Mario
>
>     @Test
>     public void testClassLoader() throws Exception {
>         // JBRULES-3630
>         File jar = new
> File("drools-compiler/src/test/resources/org/drools/compiler/xml/changeset/changeset.jar");
>         assertTrue(jar.exists());
>         ClassLoader classLoader = URLClassLoader.newInstance(new URL[]{
> jar.toURI().toURL() }, getClass().getClassLoader());
>         Resource changeSet =
> ResourceFactory.newClassPathResource("changeset1Test.xml", classLoader);
>         KnowledgeBuilderConfiguration conf =
> KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null, classLoader);
>         KnowledgeBuilder builder =
> KnowledgeBuilderFactory.newKnowledgeBuilder(conf);
>         builder.add(changeSet, ResourceType.CHANGE_SET);
>     }

Mario,

Can you also test the following, please?

// Assuming that your change set contains resource
"classpath:data/IntegrationExampleTest.xls"
URL resource1 =
getClass().getClassLoader().getResource("data/IntegrationExampleTest.xls");
Assert.assertNull(resource1);

URL resource2 = classLoader.getResouce("data/IntegrationExampleTest.xls");
Assert.assertNotNull(resource2);

The point is that the JAR that you are dynamically loading must *not*
already exist on the classpath. My patch definitely applies on the
master branch, and so I strongly doubt that this issue is fixed there.

Cheers,
Chris


More information about the rules-dev mailing list