]
Luca Molteni commented on DROOLS-6032:
--------------------------------------
[~tkobayashi] I've uploaded a patch for a first draft of using the FQCN.
I started working on it on Friday but I found a few problem with it:
- We're using static fields for constants and the methods generating Java Parser code,
and I didn't want to change all of them to non-static to get access to `isPattern`
field in the context.
- I didn't want also to add a boolean parameter to every static method, it seemed
wrong to me (and didn't solve the static constant problem)
In the end I realised that it's probably better if we remove the Flow before and try
to migrate to FQCN after, what do you think?
In the meanwhile I changed the `D` with `X` as a placeholder. We could use other
workarounds (such as renaming the `.pattern.D` class but would break backwards
compatibility.
Tell me if you take a look at the patch
I also link a related Jira issue
Class name conflict by class "D" in exec-model
----------------------------------------------
Key: DROOLS-6032
URL:
https://issues.redhat.com/browse/DROOLS-6032
Project: Drools
Issue Type: Bug
Components: executable model
Affects Versions: 7.50.0.Final
Reporter: Toshiya Kobayashi
Assignee: Toshiya Kobayashi
Priority: Major
Attachments: FQN_first_draft,_uses_static_fields.patch
If you use a fact class named "D", you will hit errors during executable-model
code generation.
{code:java}
@Test
public void testClassNameConflict() {
String str =
"import " + D.class.getCanonicalName() + ";" +
"rule R when\n" +
" D(name == \"John\")\n" +
"then\n" +
"end";
KieSession ksession = getKieSession( str );
D fact = new D("John");
ksession.insert( fact );
assertEquals(1, ksession.fireAllRules());
}
public static class D {
private String name;
public D(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
{code}
{noformat}
[ERROR]
CompilerTest.testClassNameConflict:2573->BaseModelTest.getKieSession:111->BaseModelTest.getKieSession:115->BaseModelTest.getKieContainer:119->BaseModelTest.getKieContainer:126->BaseModelTest.createKieBuilder:137->BaseModelTest.createKieBuilder:164
[Message [id=1, level=ERROR,
path=src/main/java/defaultpkg/RulesF625E96E2F948CA04652DBAC4C6DBB79.java, line=5,
column=1
text=a type with the same simple name is already defined by the single-type-import of
org.drools.modelcompiler.dsl.pattern.D], Message [id=2, level=ERROR,
path=src/main/java/defaultpkg/RulesF625E96E2F948CA04652DBAC4C6DBB79.java, line=0,
column=0
text=Java source of
src/main/java/defaultpkg/RulesF625E96E2F948CA04652DBAC4C6DBB79.java in error:
package defaultpkg;
import org.drools.modelcompiler.dsl.pattern.D;
import org.drools.model.Index.ConstraintType;
import org.drools.modelcompiler.CompilerTest.D;
...
{noformat}