예외 상황은 다음과 같다.

DEBUG - java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
 java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
 java.io.InvalidClassException: com.corecess.viewlinx.faultmanager.datatype.VarBind$Value; local class incompatible: stream classdesc serialVersionUID = 8724925862695485825, local class serialVersionUID = 3842192060962998658

수신한 원격 클래스의 serialVersionUID가 로컬 클래스의 serialVersionUID과 달라서 InvalidClassException 예외가 발생하였다.

다음을 참고하여 해결한다.

The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If the receiver has loaded a class for the object that has a different serialVersionUID than that of the corresponding sender's class, then deserialization will result in an InvalidClassException. A serializable class can declare its own serialVersionUID explicitly by declaring a field named "serialVersionUID" that must be static, final, and of type long:

 ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;

If a serializable class does not explicitly declare a serialVersionUID, then the serialization runtime will calculate a default serialVersionUID value for that class based on various aspects of the class, as described in the Java(TM) Object Serialization Specification. However, it is strongly recommended that all serializable classes explicitly declare serialVersionUID values, since the default serialVersionUID computation is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpected InvalidClassExceptions during deserialization. Therefore, to guarantee a consistent serialVersionUID value across different java compiler implementations, a serializable class must declare an explicit serialVersionUID value. It is also strongly advised that explicit serialVersionUID declarations use the private modifier where possible, since such declarations apply only to the immediately declaring class--serialVersionUID fields are not useful as inherited members.

정리하자면, serialVersionUID 값을 명시적으로 할당하지 않으면 컴파일러에 의해 묵시적인 값이 할당되는데 이는 상황에 따라 바뀔 수 있기 때문에 이에 의존하지 말고 명시적으로 할당하라는 말이다.

다음과 같은 한 줄이면 해결된다.

private static final long serialVersionUID = 1L;

Reference:
http://java.sun.com/j2se/1.5.0/docs/api/java/io/Serializable.html

Posted by 알 수 없는 사용자
,

RMI 실행시 JRE 옵션

Tips 2008. 3. 20. 11:20

-Djava.security.manager -Djava.security.policy=policy/policy
Posted by 알 수 없는 사용자
,

역순으로 정렬하고자 할 때, 다음과 같이 인자의 순서를 뒤집어서 비교할 수 있다.

public int compare(Employee e1, Employee e2) {
 return e2.hireDate().compareTo(e1.hireDate());
}

하지만 결코 다음과 같이 -를 붙여서 역순으로 정렬하면 안된다.

// Don't do this!!
return -r1.hireDate().compareTo(r2.hireDate());

왜냐하면 Integer.MIN_VALUE를 음수화한 값은 여전히 음수이기 때문이다.

Reference:
http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html

Posted by 알 수 없는 사용자
,