Vincent Bussol created JEXL-432:
-----------------------------------

             Summary: Namespace functors are not cleared when the classloader 
is updated
                 Key: JEXL-432
                 URL: https://issues.apache.org/jira/browse/JEXL-432
             Project: Commons JEXL
          Issue Type: Bug
    Affects Versions: 3.4.0
            Reporter: Vincent Bussol


Using a cache-enabled engine, when the classloader is updated, nodes with 
namespace functor values are not cleared and still use the previous version.

>From the "ClassCreatorTest" class, here is a test to illustrate the issue:
{code:java}
    @Test
    public void testFunctorFour() throws Exception {
        final ClassCreator cctor = new ClassCreator(jexl, base);
        cctor.setSeed(2);
        cctor.setCtorBody("value = (Integer) ctxt.get(\"value\") + 10;");
        Class<?> foo1 = cctor.createClass(true);
        assertSame(foo1.getClassLoader(), cctor.getClassLoader());
        assertEquals("foo2", foo1.getSimpleName());        final Map<String, 
Object> ns = new HashMap<>();
        ns.put("test", foo1.getName());
        // use cache
        final JexlEngine jexl2 = new 
JexlBuilder().namespaces(ns).cache(16).create();
        jexl2.setClassLoader(cctor.getClassLoader());
        cctor.clear();        final JexlContext ctxt = new MapContext();
        ctxt.set("value", 1000);
        final JexlScript script = jexl2.createScript("test:getValue()");
        Object result = script.execute(ctxt);
        assertEquals(1010, result);        cctor.setSeed(2);
        cctor.setCtorBody("value = (Integer) ctxt.get(\"value\") + 99;");
        final Class<?> foo11 = cctor.createClass(true);
        assertEquals("foo2", foo1.getSimpleName());
        assertNotSame(foo11, foo1);
        foo1 = foo11;
        // drum rolll....
        jexl2.setClassLoader(foo1.getClassLoader());
        result = script.execute(ctxt);
        // tada!
        assertEquals(1099, result);
    } {code}
A solution could be to add the "NamespaceFunctor" to the list of instances to 
clean (JexlNode#clearCache()).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to