-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved java.net.Authenticator cleanup and workaround for https://is…
- Loading branch information
Mattias Jiderhamn
committed
Dec 6, 2013
1 parent
63d85b1
commit 16fc362
Showing
3 changed files
with
154 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/test/java/se/jiderhamn/classloader/leak/prevention/CXFAuthenticatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package se.jiderhamn.classloader.leak.prevention; | ||
|
||
import org.apache.cxf.transport.http.CXFAuthenticator; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import se.jiderhamn.JUnitClassloaderRunner; | ||
import se.jiderhamn.LeakPreventor; | ||
|
||
/** | ||
* Test case to verify that org.apache.cxf.transport.http.CXFAuthenticator causes classloader leaks. | ||
* @author Mattias Jiderhamn | ||
*/ | ||
@RunWith(JUnitClassloaderRunner.class) | ||
@LeakPreventor(CXFAuthenticatorTest.Prevent.class) | ||
public class CXFAuthenticatorTest { | ||
|
||
@Test | ||
public void triggetCxfAuthenticatorLeak() { | ||
CXFAuthenticator.addAuthenticator(); | ||
} | ||
|
||
public static class Prevent implements Runnable { | ||
@Override | ||
public void run() { | ||
new ClassLoaderLeakPreventor() { | ||
{ | ||
clearDefaultAuthenticator(); | ||
} | ||
}; | ||
|
||
// This does not help, since WeakReference is not garbage collected until ClassLoader is GC:ed | ||
/* | ||
try { | ||
// By requesting authentication, ReferencingAuthenticator should detect that CXFAuthenticator has been removed | ||
Authenticator.requestPasswordAuthentication(null, 0, null, null, null); | ||
} | ||
catch (Exception e) { | ||
// CS:IGNORE | ||
} | ||
*/ | ||
} | ||
} | ||
} |