比较 'Object' 字段中的值时可能出现错误
Possible bug when comparing a value in an 'Object' field
我已经能够在 6.0.3 和 6.2.0 中重现此错误。我不确定解释它的最佳方式,所以我也会添加重现它的代码。
我已将代码缩减为仅会导致错误的代码。在我的原始代码中,我使用了一些其他类似的 pojo。这不是粘贴所有这些 classes,而是使用一些具有相同效果的常见 java classes。您可以使用任何 Class 虽然得到相同的错误
EventObject - 可以是任何存储 'Object' 并具有 getter 和 setter 字段的任何 class
随机 - 可以是任何 class 没有带有单个字符串参数的构造函数
整数 - 可以是任何 class
当规则比较字段中包含的值并且该字段属于 'Object' class 时,有时规则会尝试创建它正在尝试的对象的新实例将值与该值进行比较并将该值的字符串表示形式传递给构造函数。
import java.util.EventObject;
import java.util.Random;
/**
* The offending line is the comparison of the EventObjects Source (an Integer
* in this case) with the Random. Occasionally when trying to compare the two,
* the rules processor tries to find a constructor for Random that has a string.
* If it finds one, it attempts to pass String.valueOf(Integer) to the
* constructor. If it doesn't find it, a reflections error is thrown:
* java.lang.NoSuchMethodError: java.util.Random.<init>(Ljava/lang/String;)V
*
* The actual classes for the three types don't matter as long as EventObject is
* any class that contains an Object field that can be set and retrieved, and
* Random is any class that does not contain a Constructor with a single
* String argument
*/
rule "Insert objects"
dialect "java"
agenda-group "aHiddenAgenda"
when
not Integer()
then
/* add more EventObjects to increase the failure rate. 10 almost always
* works, 1000 almost never works
*/
for(int i = 0; i < 175; i++) {
insert(new EventObject(new Integer(i)));
}
for(int i = 0; i < 10; i++) {
insert(new Random());
}
end
rule "Find a Random where no EventObject contains it"
dialect "java"
agenda-group "aHiddenAgenda"
when
$toCompare : Random()
not EventObject( $toCompare == source )
then
end
好的,您遇到了 6.2.0 及更早版本中的错误。
它在我尝试过的 6.3.0 和 6.4.0 中消失了,大概是更高版本。
我已经能够在 6.0.3 和 6.2.0 中重现此错误。我不确定解释它的最佳方式,所以我也会添加重现它的代码。
我已将代码缩减为仅会导致错误的代码。在我的原始代码中,我使用了一些其他类似的 pojo。这不是粘贴所有这些 classes,而是使用一些具有相同效果的常见 java classes。您可以使用任何 Class 虽然得到相同的错误
EventObject - 可以是任何存储 'Object' 并具有 getter 和 setter 字段的任何 class
随机 - 可以是任何 class 没有带有单个字符串参数的构造函数
整数 - 可以是任何 class
当规则比较字段中包含的值并且该字段属于 'Object' class 时,有时规则会尝试创建它正在尝试的对象的新实例将值与该值进行比较并将该值的字符串表示形式传递给构造函数。
import java.util.EventObject;
import java.util.Random;
/**
* The offending line is the comparison of the EventObjects Source (an Integer
* in this case) with the Random. Occasionally when trying to compare the two,
* the rules processor tries to find a constructor for Random that has a string.
* If it finds one, it attempts to pass String.valueOf(Integer) to the
* constructor. If it doesn't find it, a reflections error is thrown:
* java.lang.NoSuchMethodError: java.util.Random.<init>(Ljava/lang/String;)V
*
* The actual classes for the three types don't matter as long as EventObject is
* any class that contains an Object field that can be set and retrieved, and
* Random is any class that does not contain a Constructor with a single
* String argument
*/
rule "Insert objects"
dialect "java"
agenda-group "aHiddenAgenda"
when
not Integer()
then
/* add more EventObjects to increase the failure rate. 10 almost always
* works, 1000 almost never works
*/
for(int i = 0; i < 175; i++) {
insert(new EventObject(new Integer(i)));
}
for(int i = 0; i < 10; i++) {
insert(new Random());
}
end
rule "Find a Random where no EventObject contains it"
dialect "java"
agenda-group "aHiddenAgenda"
when
$toCompare : Random()
not EventObject( $toCompare == source )
then
end
好的,您遇到了 6.2.0 及更早版本中的错误。
它在我尝试过的 6.3.0 和 6.4.0 中消失了,大概是更高版本。