Spring-RMI event causes java.io.InvalidClassException: filter status: REJECTED

Viewed 6279

The problem

Problem with Spring 4.3.3 and Java 8 when project uses RMI. Application throws exception during using RMI to send event to other application. It was working fine (application is few years old) but it broke after some patch installation on Weblogic server.

The code

The application uses spring-context

org.springframework.context.support.AbstractApplicationContext

 private void publishEvent(final ApplicationEvent event) {
        taskExecutor.submit(new Runnable() {
            @Override
            public void run() {
                publisher.publishEvent(event);
            }
        });
    }

The logs

> 2019-10-01 10:42:14,366 ERROR .c.b.i.i.ImportServiceImpl - An unexpected error occurred during the synchronous import process.
org.springframework.remoting.RemoteLookupFailureException: Lookup of RMI stub failed; nested exception is java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
        java.io.InvalidClassException: filter status: REJECTED
        at org.springframework.remoting.rmi.RmiClientInterceptor.lookupStub(RmiClientInterceptor.java:215)
        at org.springframework.remoting.rmi.RmiClientInterceptor.getStub(RmiClientInterceptor.java:237)
        at org.springframework.remoting.rmi.RmiClientInterceptor.invoke(RmiClientInterceptor.java:258)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

(...)       


>   Caused by: java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
        java.io.InvalidClassException: filter status: REJECTED
        at sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:125)
        at java.rmi.Naming.lookup(Naming.java:101)
        at org.springframework.remoting.rmi.RmiClientInterceptor.lookupStub(RmiClientInterceptor.java:200)
        ... 104 common frames omitted
Caused by: java.io.InvalidClassException: filter status: REJECTED
        at java.io.ObjectInputStream.filterCheck(ObjectInputStream.java:1255)
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1878)
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1751)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2042)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1573)
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2287)
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2211)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2069)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1573)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:431)
        at sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:123)
        ... 106 common frames omitted
3 Answers

I used the solution proposed above in a similiar situation and it works for me:

JAVA_OPTIONS="${JAVA_OPTIONS} -Dweblogic.oif.serialFilterScope=weblogic

You can find the description of the Weblogic settings here.

I faced the same situation when migrating from weblogic 12.1.3.0 to weblogic 12.2.1.4. Ultimately I debugged the weblogic server into java.io.ObjectInputStream#filterCheck, in debug I could see the filter being used.

Very strangely weblogic 12.2.1.4 comes with a preset filter that does not allow for java.rmi.server.* classes to be serialized .

Therefore the fix that worked for me was to add the whole package to the allowed filter:

java.rmi.server.*

Oracle documentation explains that the default behaviour will be "combine" what we define will take precedence over the predefined filter.

(windows)

set JAVA_OPTIONS=-Dweblogic.oif.serialFilter=java.rmi.server.* %JAVA_OPTIONS%

(*nix)

export JAVA_OPTIONS=-Dweblogic.oif.serialFilter=java.rmi.server.* $JAVA_OPTIONS

I did see the same thing not with the spring framework but with deploying servlet based rmi in WebLogic.

I did the code change

import java.rmi.server.*;

and added the system property

 -Dweblogic.oif.serialFilterScope=weblogic  

this worked.

Related