Skip to content

Commit

Permalink
#32 (#33)
Browse files Browse the repository at this point in the history
Signed-off-by: monicadragomir <monica.dragomir@oracle.com>
  • Loading branch information
monicadragomir authored and lukasj committed Feb 14, 2019
1 parent dd2d183 commit 16810e6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -884,6 +884,15 @@ public WSDLService getWsdlService() {
private static ClassLoader getDelegatingLoader(ClassLoader loader1, ClassLoader loader2) {
if (loader1 == null) return loader2;
if (loader2 == null) return loader1;
//If there is already a parent-child relationship between loaders,
//it does not make sense to create a new one
//The created proxy might be reusable, otherwise a new proxy is
//created on each call since a new loader is used each time
ClassLoader parent = loader1.getParent();
while (parent != null) {
if (parent == loader2) return loader1;
parent = parent.getParent();
}
return new DelegatingLoader(loader1, loader2);
}

Expand Down
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2019, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package com.sun.xml.ws.client;

import java.lang.reflect.Method;

import junit.framework.TestCase;

public class WSServiceDelegateTest extends TestCase {
public void testGetDelegatingLoader() throws Exception {
MyClassLoader loader2 = new MyClassLoader();
MyClassLoader loader1 = new MyClassLoader(loader2);
ClassLoader result = invokeGetDelegatingLoader(loader1, loader2);
assertEquals(loader1, result);

loader2 = new MyClassLoader();
loader1 = new MyClassLoader();
result = invokeGetDelegatingLoader(loader1, loader2);
assertEquals(loader2, result.getParent());

result = invokeGetDelegatingLoader(loader1, null);
assertEquals(loader1, result);

result = invokeGetDelegatingLoader(null, loader2);
assertEquals(loader2, result);
}

private ClassLoader invokeGetDelegatingLoader(ClassLoader loader1, ClassLoader loader2) throws Exception {
Method m = WSServiceDelegate.class.getDeclaredMethod("getDelegatingLoader", ClassLoader.class, ClassLoader.class);
m.setAccessible(true);
return (ClassLoader)m.invoke(WSServiceDelegate.class, loader1, loader2);
}
private static class MyClassLoader extends ClassLoader {
MyClassLoader() {}
MyClassLoader(ClassLoader parent) {super(parent);}
}
}


0 comments on commit 16810e6

Please sign in to comment.