[jboss-jira] [JBoss JIRA] (DROOLS-1404) Alpha node not shared with static function evaluation

Matteo Mortari (JIRA) issues at jboss.org
Fri Jan 13 07:37:00 EST 2017


    [ https://issues.jboss.org/browse/DROOLS-1404?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13347883#comment-13347883 ] 

Matteo Mortari commented on DROOLS-1404:
----------------------------------------

Further analysis confirms suspects as per discussion with Mario, there are actually two issues, one a false alpha node sharing, another a problem with the indexing.

Placing the following in the Misc2Test will manifest the two issues separately

{code:java}
    /**
     * Being mutable static variable holder, it's unsafe to be used concurrently from different places.
     */
    public static class UnsafeStaticValuesHolder {
        private static Object var1;
        
        public static Object getVar1() {
            return var1;
        }
        
        public static void setVar1(Object input) {
            var1 = input;
        }
        
        public static void reset() {
            var1 = null;
        }
    }
    
    @Test
    public void testShareNotConstant() {
        UnsafeStaticValuesHolder.reset();
        UnsafeStaticValuesHolder.setVar1(1);
        String drl = "package c;\n" + 
                "\n" + 
                "import " + TestObject.class.getCanonicalName() + "\n" +
                "import " + UnsafeStaticValuesHolder.class.getCanonicalName() + "\n" +
                "\n" + 
                "rule fileBrule1 when\n" + 
                "  TestObject(value == 1)\n" + 
                "then\n" + 
                "end\n" + 
                "rule fileArule1 when\n" + 
                "  TestObject(value == UnsafeStaticValuesHolder.getVar1() )\n" + 
                "then\n" + 
                "end\n" +
                ""
                ;

        KieSession kieSession = new KieHelper()
                    .addContent(drl, ResourceType.DRL)
                    .build().newKieSession();
        
        ReteDumper.dumpRete(kieSession);
        System.out.println(drl);
        kieSession.addEventListener(new DebugAgendaEventListener());

        UnsafeStaticValuesHolder.setVar1(2);
        kieSession.insert(new TestObject(1));

        assertEquals(1, kieSession.fireAllRules() );
    }
    
    @Test
    public void testShareNotConstantIndexingIssue() {
        UnsafeStaticValuesHolder.reset();
        UnsafeStaticValuesHolder.setVar1(2);
        String drl = "package c;\n" + 
                "\n" + 
                "import " + TestObject.class.getCanonicalName() + "\n" +
                "import " + UnsafeStaticValuesHolder.class.getCanonicalName() + "\n" +
                "\n" + 
                "rule fileBrule1 when\n" + 
                "  TestObject(value == 1)\n" + 
                "then\n" + 
                "end\n" + 
                "rule fileArule1 when\n" + 
                "  TestObject(value == UnsafeStaticValuesHolder.getVar1() )\n" + 
                "then\n" + 
                "end\n" +
                "rule fileArule0 when\n" + 
                "  TestObject(value == 0 )\n" + 
                "then\n" + 
                "end\n" +
                ""
                ;

        KieSession kieSession = new KieHelper()
                    .addContent(drl, ResourceType.DRL)
                    .build().newKieSession();
        
        ReteDumper.dumpRete(kieSession);
        System.out.println(drl);
        kieSession.addEventListener(new DebugAgendaEventListener());

        UnsafeStaticValuesHolder.setVar1(1);
        kieSession.insert(new TestObject(1));

        assertEquals(2, kieSession.fireAllRules() );
    }
{code}


> Alpha node not shared with static function evaluation
> -----------------------------------------------------
>
>                 Key: DROOLS-1404
>                 URL: https://issues.jboss.org/browse/DROOLS-1404
>             Project: Drools
>          Issue Type: Bug
>          Components: core engine
>            Reporter: Matteo Mortari
>            Assignee: Matteo Mortari
>
> The following code when placed in Misc2Test exhibit the problem
> {code:java}
>     public static class TestStaticUtils {
>         public static int return1() { 
>             return 1;
>         }
>     }
>     
>     @Test
>     public void testCheck2() {
>         String drl = "package c;\n" + // <<- keep this package name
>                 "\n" + 
>                 "import " + TestObject.class.getCanonicalName() + "\n" +
>                 "\n" + 
>                 "rule fileBrule1 when\n" + 
>                 "  TestObject(value == 1)\n" + 
>                 "then\n" + 
>                 "end"
>                 ;
>         
>         String drl2 = "package iTransiberian;\n" + // <<- keep this package name
>                 "\n" + 
>                 "import " + TestObject.class.getCanonicalName() + "\n" +
>                 "import " + TestStaticUtils.class.getCanonicalName() + "\n" +
>                 "\n" + 
>                 "rule fileArule1 when\n" + 
>                 "  $t : String()\n" + 
>                 "  TestObject(value == TestStaticUtils.return1() )\n" + 
>                 "then\n" + 
>                 "end\n"+ 
>                 "rule fileArule2 when\n" + // <<- keep this rule
>                 "  $t : String()\n" + 
>                 "  TestObject(value == 0 )\n" + 
>                 "then\n" + 
>                 "end\n" + 
>                 ""
>                 ;
>         KieSession kieSession = new KieHelper()
>                     .addContent(drl2, ResourceType.DRL)
>                     .addContent(drl, ResourceType.DRL)
>                     .build().newKieSession();
>         
>         ReteDumper.dumpRete(kieSession);
>         System.out.println(drl);
>         System.out.println(drl2);
>         kieSession.addEventListener(new DebugAgendaEventListener());
>         kieSession.insert("test");
>         kieSession.insert(new TestObject(1));
>         assertEquals(2, kieSession.fireAllRules() );
>     }
> {code}
> Conducting further analysis...



--
This message was sent by Atlassian JIRA
(v7.2.3#72005)


More information about the jboss-jira mailing list