diff options
Diffstat (limited to 'bundles/org.eclipse.osgi.tests/bundles_src/classloader.hooks.a/org/eclipse/osgi/tests/classloader/hooks/a/TestHookConfigurator.java')
-rw-r--r-- | bundles/org.eclipse.osgi.tests/bundles_src/classloader.hooks.a/org/eclipse/osgi/tests/classloader/hooks/a/TestHookConfigurator.java | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/classloader.hooks.a/org/eclipse/osgi/tests/classloader/hooks/a/TestHookConfigurator.java b/bundles/org.eclipse.osgi.tests/bundles_src/classloader.hooks.a/org/eclipse/osgi/tests/classloader/hooks/a/TestHookConfigurator.java index 0259d4fd2..db458e144 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/classloader.hooks.a/org/eclipse/osgi/tests/classloader/hooks/a/TestHookConfigurator.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/classloader.hooks.a/org/eclipse/osgi/tests/classloader/hooks/a/TestHookConfigurator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2016 IBM Corporation and others. + * Copyright (c) 2013, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.osgi.tests.classloader.hooks.a; +import org.eclipse.osgi.container.Module; import org.eclipse.osgi.internal.hookregistry.*; import org.eclipse.osgi.internal.loader.classpath.ClasspathEntry; import org.eclipse.osgi.internal.loader.classpath.ClasspathManager; @@ -18,6 +19,13 @@ import org.eclipse.osgi.storage.bundlefile.BundleEntry; public class TestHookConfigurator implements HookConfigurator { private static final String REJECT_PROP = "classloader.hooks.a.reject"; private static final String BAD_TRANSFORM_PROP = "classloader.hooks.a.bad.transform"; + private static final String RECURSION_LOAD = "classloader.hooks.a.recursion.load"; + private static final String RECURSION_LOAD_SUPPORTED = "classloader.hooks.a.recursion.load.supported"; + final ThreadLocal<Boolean> doingRecursionLoad = new ThreadLocal<Boolean>() { + protected Boolean initialValue() { + return false; + }; + }; public void addHooks(HookRegistry hookRegistry) { hookRegistry.addClassLoaderHook(new ClassLoaderHook() { @@ -32,9 +40,34 @@ public class TestHookConfigurator implements HookConfigurator { if (Boolean.getBoolean(BAD_TRANSFORM_PROP)) { return new byte[] {'b', 'a', 'd', 'b', 'y', 't', 'e', 's'}; } + if (Boolean.getBoolean(RECURSION_LOAD)) { + if (isProcessClassRecursionSupported() && doingRecursionLoad.get()) { + return null; + } + Module m = manager.getGeneration().getBundleInfo().getStorage().getModuleContainer().getModule(1); + doingRecursionLoad.set(true); + try { + m.getCurrentRevision().getWiring().getClassLoader().loadClass("substitutes.x.Ax"); + if (!isProcessClassRecursionSupported()) { + throw new LinkageError("Recursion is no supported."); + } + } catch (ClassNotFoundException e) { + if (isProcessClassRecursionSupported()) { + throw new LinkageError("Recursion should be supported."); + } + // expected + } finally { + doingRecursionLoad.set(false); + } + } return null; } + @Override + public boolean isProcessClassRecursionSupported() { + return Boolean.getBoolean(RECURSION_LOAD_SUPPORTED); + } + }); } } |