dragome/dragome-sdk

Array [] getClass bug

Closed this issue · 2 comments

After digging I think managed to reproduce this warning that any 3d examples show (Ex: http://xpenatan.github.io/gdx-dragome-backend/index.html?Gears) that it shows "java.lang.ClassNotFoundException: com_badlogic_gdx_graphics_g3d_environment_Spotight;" dont exist. There is no Spotight but there is SpotLight. The code below when is executed "MyItem" overrides MyItemTest array getClass call. Its similar to gears demo that it should be a String array type and not Spotight.

public class MyItem {
}

public class MyItemTest<T> {
    public T[] items;

    public MyItemTest () {
        items = (T[])new Object[8];
    }

    public void testBug () {
        T[] items = this.items;
        Class<? extends Object[]> class1 = items.getClass();
        Class<?> componentType = class1.getComponentType();
        System.out.println("Type: " + class1);
    }
}

public void test() {
        MyItemTest<String> test = new MyItemTest<>();
        MyItem [] items = new MyItem[5];
        test.testBug();
}

It prints " Type: class [Lcom.badlogic.gdx.tests.dragome.examples.MyItem; "

Edit: changing the order of MyItem it prints " [Ljava.lang.Object " ex:

MyItem [] items = new MyItem[5];
MyItemTest<String> test = new MyItemTest<>();
test.testBug();

There is other bug that happens when calling getComponentType. Executing the code will print "nextClass is null" and a exception will throw.

@DragomeCompilerSettings(CompilerType.Strict)
public void equalTest() {
        Class clazz = String.class;
        Object [] t = new Object[10];
        Class<? extends Object[]> class1 = t.getClass();
        Class<?> componentType = class1.getComponentType();
        Class nextClass = String.class;
        while (nextClass != Object.class) {
            if(nextClass == null) {
                System.out.println("nextClass is null");
            }
            nextClass = nextClass.getSuperclass();
        }
}

getComponentType is messing up with java.lang.Object and the comparison is failing.

Look at image below, __r3 dont have the same attributes as __r5. __r3 have ";" in realname.

compare

removing ";" from type in forName fixed the 2nd array bug

String type= className.replaceAll("\\[", "");
type = type.replaceAll(";", "");

but not the first bug