package nallar.tickthreading.util.contextaccess;

import nallar.tickthreading.Log;
import nallar.tickthreading.util.EnvironmentInfo;

class ContextAccessProvider {
	private static final Class[] contextAccessClasses = {
			ContextAccessReflection.class,
			ContextAccessSecurityManager.class,
	};

	static ContextAccess getContextAccess() {
		for (Class<?> clazz : contextAccessClasses) {
			try {
				ContextAccess contextAccess = (ContextAccess) clazz.newInstance();
				Class<?> currentClass = contextAccess.getContext(0);
				if (currentClass != ContextAccessProvider.class) {
					StringBuilder sb = new StringBuilder();
					sb.append("Stack:\n");
					for (int i = -2; i < 3; i++) {
						try {
							sb.append(contextAccess.getContext(i).getName()).append(" at ").append(i).append('\n');
						} catch (Throwable ignored) {
						}
					}
					throw new Error("Wrong class returned: " + currentClass + ", expected ContextAccessProvider. " + sb);
				}
				return contextAccess;
			} catch (Throwable t) {
				Log.warning("Unable to set up context access class " + clazz + ". " + t.getMessage() + ", falling back to slower context access. On JRE: " + EnvironmentInfo.getJavaVersion());
			}
		}
		throw new Error("Failed to set up any context access");
	}
}

@@ -1043,18 +1043,39 @@
 %09%09%09%09
-Log.warnin
+if (Log.debug) %7B%0D%0A%09%09%09%09%09Log.debu
 g(%22U
@@ -1237,16 +1237,23 @@
 on());%0D%0A
+%09%09%09%09%7D%0D%0A
 %09%09%09%7D%0D%0A%09%09

Fix #846