6.0.3 및 6.2.0에서이 오류를 다시 만들 수있었습니다. 나는 그것을 설명하기위한 최선의 방법이 확실하지 않으므로 그것을 재현하는 코드도 추가 할 것이다.'Object'필드의 값을 비교할 때 발생할 수있는 버그
코드를 작성하여 오류의 원인을 찾아 냈습니다. 내 원래 코드에서는 비슷한 다른 pojos를 사용합니다. 이러한 모든 클래스를 붙여 넣는 대신 동일한 효과를 갖는 일반적인 Java 클래스를 사용합니다. 하지 않는 클래스가 될 수 있습니다 -에 '객체'를 저장하고 해당 필드
임의의 getter와 setter가있는 모든 클래스가 될 수 있습니다 - 같은 오류를
은 EventObject를 얻을 수 있지만 당신은 어떤 클래스를 사용할 수 있습니다 단일 문자열 인수
정수와 생성자 - 규칙이 필드에 포함 된 값을 비교하면 모든 클래스
될 수 있고, 필드는 '객체'클래스이며, 때로는 규칙에 시도 값을 비교하려고하는 객체의 새 인스턴스를 만들고 그 객체의 String 표현을 전달합니다. 값을 생성자에 추가합니다.
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
java.util.Random과 EventObject.source를 비교하는 것은 매우 이상한 생각입니다. 이 이상한 규칙으로 무엇을 성취하려고합니까? – laune
나는 그 클래스를 선택하여 일반적인 자바 객체를 사용하고 버그는 쉽게 재현 할 수있다. 그 곳에서 어떤 수업이라도 사용할 수 있습니다. 내가 만든 POJO를 사용했다는 것을 발견했다. – mike
버그가 없다. WM에는 175 개의 EventObject 사실과 10 개의 임의의 사실이 있습니다. 그들은 공통점이 없습니다. – laune