From 02d0a9afd56811e9c555c0a3f91cc3a4476d38b3 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Sat, 9 Feb 2013 16:50:42 +0100 Subject: [PATCH] Add some debug information to a OutOfMemory exception. --- .../protocol/reflect/compiler/StructureCompiler.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/StructureCompiler.java b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/StructureCompiler.java index 579c069a..13d90652 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/StructureCompiler.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/StructureCompiler.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.reflect.StructureModifier; import com.google.common.base.Objects; import com.google.common.primitives.Primitives; @@ -206,6 +207,11 @@ public final class StructureCompiler { return (StructureModifier) compiledClass.getConstructor( StructureModifier.class, StructureCompiler.class). newInstance(source, this); + } catch (OutOfMemoryError e) { + // Print the number of generated classes by the current instances + ProtocolLibrary.getErrorReporter().reportWarning( + this, "May have generated too many classes (count: " + compiledCache.size() + ")"); + throw e; } catch (IllegalArgumentException e) { throw new IllegalStateException("Used invalid parameters in instance creation", e); } catch (SecurityException e) { @@ -218,7 +224,7 @@ public final class StructureCompiler { throw new RuntimeException("Error occured while instancing generated class.", e); } catch (NoSuchMethodException e) { throw new IllegalStateException("Cannot happen.", e); - } + } } /**