Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Threads may overwrite defineClassMethod in getDefineClassMethod method of AccessClassLoader #62

Closed
detective0922 opened this issue Jul 19, 2018 · 0 comments

Comments

@detective0922
Copy link

	private static Method getDefineClassMethod() throws Exception {
		// DCL on volatile
		if (defineClassMethod==null) {
			synchronized(accessClassLoaders) {
				defineClassMethod = ClassLoader.class.getDeclaredMethod("defineClass", new Class[] {String.class, byte[].class, int.class,
				int.class, ProtectionDomain.class});
				try {
					defineClassMethod.setAccessible(true);
				}
				catch (Exception ignored) {
				}
			}
		}
		return defineClassMethod;
	}

When Thread 1 assign a value to defineClassMethod and leave the critical section, then Thread 2 may assign a new value to defineClassMethod.
Maybe should check defineClassMethod==null inside synchronized(accessClassLoaders) code block too to avoid this issue and complete the DCL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant