NPE in FieldSerializer

This simple test case produces a NPE with the master branch and in beta2. When I debug the class with Intellij it seems that savedCtors in FieldSerializer is null. But I can’t understand why because it should be initialized in this line:

private static Map<Class, Constructor> savedCtors = new HashMap<Class, Constructor>();

I’m very confused now.

import com.jme3.network.serializing.Serializer;
import com.jme3.network.serializing.serializers.FieldSerializer;

public class SerializerTest {
    static {
        Serializer.registerClass(Object.class, new FieldSerializer());
    }
    public static void main(String[] args) {}
}
Exception in thread "main" java.lang.ExceptionInInitializerError
	at com.jvpichowski.SerializerTest.<clinit>(SerializerTest.java:13)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)
Caused by: java.lang.NullPointerException
	at com.jme3.network.serializing.serializers.FieldSerializer.checkClass(FieldSerializer.java:62)
	at com.jme3.network.serializing.serializers.FieldSerializer.initialize(FieldSerializer.java:85)
	at com.jme3.network.serializing.Serializer.registerClassForId(Serializer.java:206)
	at com.jme3.network.serializing.Serializer.registerClass(Serializer.java:304)
	at com.jme3.network.serializing.Serializer.getSerializerRegistration(Serializer.java:361)
	at com.jme3.network.serializing.Serializer.getSerializer(Serializer.java:316)
	at com.jme3.network.serializing.Serializer.registerClass(Serializer.java:228)
	at com.jme3.network.serializing.Serializer.registerClass(Serializer.java:152)
	at com.jme3.network.serializing.Serializer.<clinit>(Serializer.java:138)
	... 4 more

Does this test fail with your setup and do you guys have any ideas?

It makes no sense to register a serializer for Object.class.

Edit: and I have no idea why you get an NPE. Funky bad Java-magic (maybe incremental compile bug?)… if the accessed class doesn’t have its static initializers initialized first. That’s bad.

Edit 2: try moving the registration line inside main().

I tried to make a very simple test case. I looked at your es-net example and there is this line which produces the same error:

 Serializer.registerClass(Name.class, new FieldSerializer());

My main goal is to get that example working. Do I have to register my components in this way?

Now I created a clean new project with BootMonnkey. It contains only this two classes:

public class Name {

    public String name;

    public Name(){
        name = "";
    }

    public Name(String name){
        this.name = name;
    }

    public String getName() {
        return name;
    }
}

and

import com.jme3.network.serializing.Serializer;
import com.jme3.network.serializing.serializers.FieldSerializer;

public class Main {

    public static void main( String... args ) {
        Serializer.registerClass(Name.class, new FieldSerializer());
    }
}

It sadly doesn’t work yet. Is there anything missing like an annotation in the Name class?

Edit: Or is it generally wrong how I try to register my components to the network?

That should work. I’m not sure why it isn’t.

If the examples are also failing then there is definitely something weird going on. Those all work fine for me.