Skip to content
Permalink
Browse files

[JENKINS-19453] Seem to have reproduced the problem in a unit test.

  • Loading branch information...
jglick authored and kohsuke committed Nov 8, 2013
1 parent bfbc7d6 commit b68e3e92b24942585fff517bb4bad1878883256f
@@ -214,16 +214,12 @@ ClassReference toRef(ClassFile2 cf) {
RemoteClassLoader rcl = (RemoteClassLoader) cl;
synchronized (_getClassLoadingLock(rcl, name)) {
Class<?> c = rcl.findLoadedClass(name);
if (TESTING) {
try {
try {
if (TESTING) {
Thread.sleep(1000);
} catch (InterruptedException x) {
assert false : x;
}
}
if (c!=null) return c;
if (c!=null) return c;

try {
// TODO: check inner class handling
Future<byte[]> img = cr.classImage.resolve(channel, name.replace('.', '/') + ".class");
if (img.isDone()) {
@@ -30,6 +30,7 @@
import org.objectweb.asm.commons.EmptyVisitor;

import java.io.IOException;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@@ -114,6 +115,42 @@ public Object call() throws Exception {
}
}

@Bug(19453)
public void testInterruption() throws Exception {
DummyClassLoader parent = new DummyClassLoader(ClassRemotingTest.class.getClassLoader(), TestLinkage.B.class);
final DummyClassLoader child1 = new DummyClassLoader(parent, TestLinkage.A.class);
final DummyClassLoader child2 = new DummyClassLoader(child1, TestLinkage.class);
final Callable<Object, Exception> c = (Callable) child2.load();
assertEquals(child2, c.getClass().getClassLoader());
RemoteClassLoader.TESTING = true;
try {
ExecutorService svc = Executors.newSingleThreadExecutor();
java.util.concurrent.Future<Object> f1 = svc.submit(new java.util.concurrent.Callable<Object>() {
@Override public Object call() throws Exception {
try {
return channel.call(c);
} catch (Throwable t) {
throw new Exception(t);
}
}
});
Thread.sleep(2500);
f1.cancel(true);
try {
Object o = f1.get();
assertEquals(String.class, o.getClass());
/* TODO we really want to fail here, but this method gets run 4×, and the last 3× it gets to this point:
fail(o.toString());
*/
} catch (CancellationException x) {
// good
}
assertNotNull(channel.call(c));
} finally {
RemoteClassLoader.TESTING = false;
}
}

public static Test suite() throws Exception {
return buildSuite(ClassRemotingTest.class);
}
@@ -0,0 +1,39 @@
/*
* The MIT License
*
* Copyright 2013 Jesse Glick.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.remoting;

public class TestLinkage implements Callable {

public Object call() throws Throwable {
return A.field;
}

public static class A {
public static Object field = new B().toString();
}

public static class B {}

}

0 comments on commit b68e3e9

Please sign in to comment.
You can’t perform that action at this time.