Skip to content

Commit

Permalink
Put warnings about inconsistent transformation results behind "nallar…
Browse files Browse the repository at this point in the history
….LaunchClassLoaderUtil.warnForInconsistentTransformation" system property
  • Loading branch information
LunNova committed Jun 22, 2016
1 parent d8ab988 commit 26942d4
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/main/java/me/nallar/modpatcher/LaunchClassLoaderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ public enum LaunchClassLoaderUtil {
private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("legacy.debugClassLoading", "false"));
private static final boolean DEBUG_FINER = DEBUG && Boolean.parseBoolean(System.getProperty("legacy.debugClassLoadingFiner", "false"));
private static final String ALREADY_LOADED_PROPERTY_NAME = "nallar.LaunchClassLoaderUtil.alreadyLoaded";
private static final String WARN_INCONSISTENT_TRANSFORMATION_PROPERTY_NAME = "nallar.LaunchClassLoaderUtil.warnForInconsistentTransformation";
private static final HashMap<String, byte[]> cachedSrgClasses = new HashMap<String, byte[]>();
static LaunchClassLoader instance;

private static List<IClassTransformer> transformers;
private static IClassNameTransformer renameTransformer;
private static Set<String> classLoaderExceptions;
private static Set<String> transformerExceptions;
private static boolean warnedForInconsistentTransformation;

static {
boolean alreadyLoaded = System.getProperty(ALREADY_LOADED_PROPERTY_NAME) != null;
Expand Down Expand Up @@ -172,10 +174,26 @@ public static void cacheSrgBytes(String transformedName, byte[] bytes) {
byte[] old = cachedSrgClasses.put(transformedName, bytes);
if (old != null && !Arrays.equals(bytes, old)) {
ModPatcherTransformer.pool.dropCache(transformedName);
PatcherLog.error(null, new Error("Inconsistent transformation results. Tried to cache different bytes for class " + transformedName + " to previous result after transformation."));
if (shouldWarnInconsistentTransformation())
PatcherLog.warn(null, new Error("Inconsistent transformation results. Tried to cache different bytes for class " + transformedName + " to previous result after transformation."));
}
}

private static boolean shouldWarnInconsistentTransformation() {
if (System.getProperty(WARN_INCONSISTENT_TRANSFORMATION_PROPERTY_NAME) != null)
return true;

if (!warnedForInconsistentTransformation) {
// non-threadsafe but it really doesn't matter if this shows up twice so I don't care
warnedForInconsistentTransformation = true;

PatcherLog.warn("One or more classes have inconsistent transformation results. To enable logging of this," +
" add -D" + WARN_INCONSISTENT_TRANSFORMATION_PROPERTY_NAME + "=true to your JVM parameters.");
}

return false;
}

public static byte[] getClassBytes(String name) {
if (name.startsWith("java/")) {
return null;
Expand Down

0 comments on commit 26942d4

Please sign in to comment.