You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 26, 2018. It is now read-only.
Repository navigation
This repository was archived by the owner on May 26, 2018. It is now read-only.
ClassCastException when calling Block.class from JUnit test #566
I'm currently trying to create a JUnit test for objects in the world. To do this i've created a fake world to mess around in. The world code works well enough that i can get results out of it as needed. Issue is i keep getting this crashing any time ModClassLoader tries to create itself. Which i've figured out how to avoid for the most part but some code doesn't allow me to avoid it. Mainly anything that tries to populate crash reports with instance information.
line 46 in ModClassLoader
this.mainClassLoader = (LaunchClassLoader)parent;
Caused by: java.lang.ClassCastException: sun.misc.Launcher$AppClassLoader cannot be cast to net.minecraft.launchwrapper.LaunchClassLoader
at cpw.mods.fml.common.ModClassLoader.(ModClassLoader.java:46)
at cpw.mods.fml.common.Loader.(Loader.java:181)
at cpw.mods.fml.common.Loader.instance(Loader.java:160)
at cpw.mods.fml.common.FMLCommonHandler.(FMLCommonHandler.java:87)
at cpw.mods.fml.common.FMLCommonHandler.(FMLCommonHandler.java:77)
... 31 more
Possible fix?
I'm most likely wrong on this but maybe an instanceof check could be added. This way JUnit tests can at least create the instance even if it doesn't function.
The problem is that many things don't work when not loaded through the LaunchClassLoader. Because many things (Events, etc.) need the ClassTransformers to work, which only work with the LaunchClassLoader.
Its true that many things need the class loader to work but i'm trying to work around that. Which for my original issue i figured out but it seems odd that so much code tries to self create the class loader. It should be null until created to allow for JUnit testing. As i can always throw up NPE checks in my code.
When you do junit testing, MC is bit started with the standard tweaking.. So having a custom tweaker just for junit testing won't really help. I also don't know how junit does its classloading..
Activity
diesieben07 commentedon Nov 20, 2014
The problem is that many things don't work when not loaded through the LaunchClassLoader. Because many things (Events, etc.) need the ClassTransformers to work, which only work with the LaunchClassLoader.
DarkGuardsman commentedon Nov 20, 2014
Its true that many things need the class loader to work but i'm trying to work around that. Which for my original issue i figured out but it seems odd that so much code tries to self create the class loader. It should be null until created to allow for JUnit testing. As i can always throw up NPE checks in my code.
jeffreykog commentedon Nov 20, 2014
You can create a special testing tweaker and launch junit through launchwrapper
DarkGuardsman commentedon Nov 20, 2014
Do you have an example of that, and can this be done threw gradle? I also rather avoid creating an instance of MC if that is what it does.
jeffreykog commentedon Nov 20, 2014
Well. I think this does not belong in your code. ForgeGradle should provide a tweaker that helps you with that. @AbrarSyed wdyt?
AbrarSyed commentedon Nov 20, 2014
When you do junit testing, MC is bit started with the standard tweaking.. So having a custom tweaker just for junit testing won't really help. I also don't know how junit does its classloading..