Skip to content

Commit

Permalink
As requested by QA, I am reverting commit: "Bug 724350 : JBRULES-3219…
Browse files Browse the repository at this point in the history
… : fixing bug when the property name starts with a lower case letter followed by an upper case one."

This reverts commit 10f4a0e.
  • Loading branch information
etirelli committed Oct 4, 2011
1 parent 10f4a0e commit 177c65a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1261,33 +1261,6 @@ public void testUppercaseField() throws Exception {
ksession.dispose();
}

@Test
public void testUppercaseField2() throws Exception {
String rule = "package org.drools\n" +
"declare SomeFact\n" +
" Field : String\n" +
" aField : String\n" +
"end\n" +
"rule X\n" +
"when\n" +
" SomeFact( Field == \"foo\", aField == \"bar\" )\n" +
"then\n" +
"end\n";
KnowledgeBase kbase = loadKnowledgeBaseFromString( rule );
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

FactType factType = kbase.getFactType("org.drools", "SomeFact");
Object fact = factType.newInstance();
factType.set(fact, "Field", "foo");
factType.set(fact, "aField", "bar");

ksession.insert(fact);
int rules = ksession.fireAllRules();

assertEquals(1, rules);
ksession.dispose();
}

@Test
public void testNullHandling() throws Exception {
final PackageBuilder builder = new PackageBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,8 @@ public BaseClassFieldReader getClassFieldReader(final Class< ? > clazz,
inspectors.put( clazz,
inspector );
}
Class< ? > fieldType = (Class< ? >) inspector.getFieldTypes().get( fieldName );
Method getterMethod = (Method) inspector.getGetterMethods().get( fieldName );
Integer index = (Integer) inspector.getFieldNames().get( fieldName );
if ( fieldType == null && fieldName.length() > 1 && Character.isLowerCase( fieldName.charAt( 0 ) ) && Character.isUpperCase( fieldName.charAt(1) ) ) {
// it might be that odd case of javabeans naming conventions that does not use lower case first letters if the second is uppercase
String altFieldName = Character.toUpperCase( fieldName.charAt( 0 ) ) + fieldName.substring( 1 );
fieldType = (Class< ? >) inspector.getFieldTypes().get( altFieldName );
if( fieldType != null ) {
// it seems it is the corner case indeed.
getterMethod = (Method) inspector.getGetterMethods().get( altFieldName );
index = (Integer) inspector.getFieldNames().get( altFieldName );
}
}
final Class< ? > fieldType = (Class< ? >) inspector.getFieldTypes().get( fieldName );
final Method getterMethod = (Method) inspector.getGetterMethods().get( fieldName );
if ( fieldType != null && getterMethod != null ) {
final String className = ClassFieldAccessorFactory.BASE_PACKAGE + "/" + Type.getInternalName( clazz ) + Math.abs( System.identityHashCode( clazz ) ) + "$" + getterMethod.getName();

Expand All @@ -139,6 +128,7 @@ public BaseClassFieldReader getClassFieldReader(final Class< ? > clazz,
bytes,
PROTECTION_DOMAIN );
// instantiating target class
final Integer index = (Integer) inspector.getFieldNames().get( fieldName );
final ValueType valueType = ValueType.determineValueType( fieldType );
final Object[] params = {index, fieldType, valueType};
return (BaseClassFieldReader) newClass.getConstructors()[0].newInstance( params );
Expand Down Expand Up @@ -167,14 +157,7 @@ public BaseClassFieldWriter getClassFieldWriter(final Class< ? > clazz,
inspectors.put( clazz,
inspector );
}
Method setterMethod = (Method) inspector.getSetterMethods().get( fieldName );
Integer index = (Integer) inspector.getFieldNames().get( fieldName );
if ( setterMethod == null && fieldName.length() > 1 && Character.isLowerCase( fieldName.charAt( 0 ) ) && Character.isUpperCase( fieldName.charAt(1) ) ) {
// it might be that odd case of javabeans naming conventions that does not use lower case first letters if the second is uppercase
String altFieldName = Character.toUpperCase( fieldName.charAt( 0 ) ) + fieldName.substring( 1 );
setterMethod = (Method) inspector.getSetterMethods().get( altFieldName );
index = (Integer) inspector.getFieldNames().get( altFieldName );
}
final Method setterMethod = (Method) inspector.getSetterMethods().get( fieldName );
if ( setterMethod != null ) {
final Class< ? > fieldType = setterMethod.getParameterTypes()[0];
final String className = ClassFieldAccessorFactory.BASE_PACKAGE + "/" + Type.getInternalName( clazz ) + Math.abs( System.identityHashCode( clazz ) ) + "$" + setterMethod.getName();
Expand All @@ -192,6 +175,7 @@ public BaseClassFieldWriter getClassFieldWriter(final Class< ? > clazz,
bytes,
PROTECTION_DOMAIN );
// instantiating target class
final Integer index = (Integer) inspector.getFieldNames().get( fieldName );
final ValueType valueType = ValueType.determineValueType( fieldType );
final Object[] params = {index, fieldType, valueType};
return (BaseClassFieldWriter) newClass.getConstructors()[0].newInstance( params );
Expand Down

0 comments on commit 177c65a

Please sign in to comment.