vaadin / kubernetes-kit

Other
3 stars 3 forks source link

SpringTransientHandler getFieldValue logs at DEBUG #107

Closed jorgheymans closed 8 months ago

jorgheymans commented 8 months ago

A couple of days ago we had gigantic log spam because of below serialization problem and deploying the application with DEBUG log level for Vaadin.

 Cannot access field keySet of class class com.vaadin.flow.internal.nodefeature.NodeMap$HashMapValuesjava.lang.reflect.InaccessibleObjectException: Unable to make field transient java.util.Set java.util.AbstractMap.keySet accessible: module java.base does not "opens java.util" to unnamed module @38143147
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
    at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
    at com.vaadin.kubernetes.starter.sessiontracker.serialization.SpringTransientHandler.getFieldValue(SpringTransientHandler.java:114)
    at com.vaadin.kubernetes.starter.sessiontracker.serialization.SpringTransientHandler.detectBean(SpringTransientHandler.java:75)
    at com.vaadin.kubernetes.starter.sessiontracker.serialization.SpringTransientHandler.lambda$inspect$2(SpringTransientHandler.java:70)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
    at com.vaadin.kubernetes.starter.sessiontracker.serialization.SpringTransientHandler.inspect(SpringTransientHandler.java:71)
    at com.vaadin.kubernetes.starter.sessiontracker.serialization.TransientInjectableObjectOutputStream.replaceObject(TransientInjectableObjectOutputStream.java:247)
    at java.base/java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1147)
    at java.base/java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1572)
    at java.base/java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1529)
    at java.base/java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1438)
    at java.base/java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1181)
    at java.base/java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1572)
    at java.base/java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1529)
    at java.base/java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1438)
    at java.base/java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1181)
    at java.base/java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:350)
    at java.base/java.util.HashMap.internalWriteEntries(HashMap.java:1944)
    at java.base/java.util.HashMap.writeObject(HashMap.java:1497)
    at java.base/jdk.internal.reflect.GeneratedMethodAccessor214.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at java.base/java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1070)
    at java.base/java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1516)
    at java.base/java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1438)
    at java.base/java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1181)
    at java.base/java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1572)

Since the method in question already comments that the exception is more or less expected, maybe it's better to log this at TRACE (just like the rest of the methods in that class do).

    private Object getFieldValue(Object target, Field field) {
        try {
            field.setAccessible(true);
            return field.get(target);
        } catch (InaccessibleObjectException | IllegalAccessException e) {
            // TODO: InaccessibleObjectException happens with Java 17
            // when inspecting Vaadin NodeMap$HashMapValues that extends HashMap
            // Should we exclude some packages by default?
            // Should we throw or ignore the error?
            getLogger().debug("Cannot access field {} of class {}",
                    field.getName(), target.getClass(), e);
        }
        return null;
    }