From bfc14ddc5425710aeb9af7c1cf9e1870915c7c93 Mon Sep 17 00:00:00 2001 From: thatsIch Date: Sun, 5 Oct 2014 15:24:29 +0200 Subject: [PATCH 1/4] Use correct way to check if layerInterface is in the map --- src/main/java/appeng/core/api/ApiPart.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/appeng/core/api/ApiPart.java b/src/main/java/appeng/core/api/ApiPart.java index ce98da3f..eb4540bc 100644 --- a/src/main/java/appeng/core/api/ApiPart.java +++ b/src/main/java/appeng/core/api/ApiPart.java @@ -1,6 +1,7 @@ package appeng.core.api; import java.io.InputStream; +import java.lang.reflect.Method; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; @@ -41,10 +42,7 @@ import com.google.common.base.Joiner; public class ApiPart implements IPartHelper { - int classNum = 1; - final HashMap TileImplementations = new HashMap(); - HashMap readerCache = new HashMap(); final HashMap interfaces2Layer = new HashMap(); final HashMap roots = new HashMap(); @@ -68,10 +66,8 @@ public class ApiPart implements IPartHelper ClassLoader loader = getClass().getClassLoader();// ClassLoader.getSystemClassLoader(); Class root = ClassLoader.class; Class cls = loader.getClass(); - java.lang.reflect.Method defineClassMethod = root.getDeclaredMethod( "defineClass", - new Class[] { String.class, byte[].class, int.class, int.class } ); - java.lang.reflect.Method runTransformersMethod = cls - .getDeclaredMethod( "runTransformers", new Class[] { String.class, String.class, byte[].class } ); + Method defineClassMethod = root.getDeclaredMethod( "defineClass", new Class[] { String.class, byte[].class, int.class, int.class } ); + Method runTransformersMethod = cls.getDeclaredMethod( "runTransformers", new Class[] { String.class, String.class, byte[].class } ); runTransformersMethod.setAccessible( true ); defineClassMethod.setAccessible( true ); @@ -330,9 +326,10 @@ public class ApiPart implements IPartHelper { try { - if ( interfaces2Layer.get( layerInterface ) == null ) + final Class layerInterfaceClass = Class.forName( layerInterface ); + if ( interfaces2Layer.get( layerInterfaceClass ) == null ) { - interfaces2Layer.put( Class.forName( layerInterface ), layer ); + interfaces2Layer.put( layerInterfaceClass, layer ); desc.add( layerInterface ); return true; } From 13cf7e7b50ea943a0b02c2436bfd6c7f15b2430a Mon Sep 17 00:00:00 2001 From: thatsIch Date: Sun, 5 Oct 2014 15:25:09 +0200 Subject: [PATCH 2/4] Reduce visibility of fields --- src/main/java/appeng/core/api/ApiPart.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/appeng/core/api/ApiPart.java b/src/main/java/appeng/core/api/ApiPart.java index eb4540bc..30f61073 100644 --- a/src/main/java/appeng/core/api/ApiPart.java +++ b/src/main/java/appeng/core/api/ApiPart.java @@ -2,10 +2,7 @@ package appeng.core.api; import java.io.InputStream; import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; +import java.util.*; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; @@ -42,11 +39,10 @@ import com.google.common.base.Joiner; public class ApiPart implements IPartHelper { - final HashMap TileImplementations = new HashMap(); - final HashMap interfaces2Layer = new HashMap(); - final HashMap roots = new HashMap(); - - final List desc = new LinkedList(); + private final Map TileImplementations = new HashMap(); + private final Map interfaces2Layer = new HashMap(); + private final Map roots = new HashMap(); + private final List desc = new LinkedList(); public void initFMPSupport() { From 6b7e821e7c55ab74032a15cb8303c9dc2cbaaa58 Mon Sep 17 00:00:00 2001 From: thatsIch Date: Sun, 5 Oct 2014 15:25:36 +0200 Subject: [PATCH 3/4] lower case field --- src/main/java/appeng/core/api/ApiPart.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/appeng/core/api/ApiPart.java b/src/main/java/appeng/core/api/ApiPart.java index 30f61073..a5b49049 100644 --- a/src/main/java/appeng/core/api/ApiPart.java +++ b/src/main/java/appeng/core/api/ApiPart.java @@ -39,7 +39,7 @@ import com.google.common.base.Joiner; public class ApiPart implements IPartHelper { - private final Map TileImplementations = new HashMap(); + private final Map tileImplementations = new HashMap(); private final Map interfaces2Layer = new HashMap(); private final Map roots = new HashMap(); private final List desc = new LinkedList(); @@ -123,11 +123,11 @@ public class ApiPart implements IPartHelper String description = base + ":" + Joiner.on( ";" ).skipNulls().join( desc.iterator() ); - if ( TileImplementations.get( description ) != null ) + if ( tileImplementations.get( description ) != null ) { try { - return TileImplementations.get( description ); + return tileImplementations.get( description ); } catch (Throwable t) { @@ -175,7 +175,7 @@ public class ApiPart implements IPartHelper f = myCLass.getName(); } - TileImplementations.put( description, myCLass ); + tileImplementations.put( description, myCLass ); try { From d889dda406721a1893bc32beb6835c7621453d99 Mon Sep 17 00:00:00 2001 From: thatsIch Date: Sun, 5 Oct 2014 15:28:55 +0200 Subject: [PATCH 4/4] Add correct types for classes to show that its really unknown at runtime which classes they use --- src/main/java/appeng/core/api/ApiPart.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/appeng/core/api/ApiPart.java b/src/main/java/appeng/core/api/ApiPart.java index a5b49049..5a2505d4 100644 --- a/src/main/java/appeng/core/api/ApiPart.java +++ b/src/main/java/appeng/core/api/ApiPart.java @@ -40,7 +40,7 @@ public class ApiPart implements IPartHelper { private final Map tileImplementations = new HashMap(); - private final Map interfaces2Layer = new HashMap(); + private final Map, String> interfaces2Layer = new HashMap, String>(); private final Map roots = new HashMap(); private final List desc = new LinkedList(); @@ -60,8 +60,8 @@ public class ApiPart implements IPartHelper try { ClassLoader loader = getClass().getClassLoader();// ClassLoader.getSystemClassLoader(); - Class root = ClassLoader.class; - Class cls = loader.getClass(); + Class root = ClassLoader.class; + Class cls = loader.getClass(); Method defineClassMethod = root.getDeclaredMethod( "defineClass", new Class[] { String.class, byte[].class, int.class, int.class } ); Method runTransformersMethod = cls.getDeclaredMethod( "runTransformers", new Class[] { String.class, String.class, byte[].class } );