Blob Blame History Raw
From 992b95828e2efe54f30d81c1418e997215ed22b5 Mon Sep 17 00:00:00 2001
From: Jakub Filak <jfilak@redhat.com>
Date: Wed, 29 Oct 2014 14:07:10 +0100
Subject: [PATCH] Fix a deadlock in RemoteTest

Related to #42
---
 test/CMakeLists.txt            |  1 +
 test/RemoteTest.java           | 12 ++++++++++--
 test/outputs/run_remote.log.in |  4 ++--
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 4e69049..5bb2b2d 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -106,6 +106,7 @@ function(_add_test_target target_name)
     add_custom_target(
         ${target_name}
         ${pre_command}
+# -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n + jdb -attach 8001
         COMMAND LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src ${Java_JAVA_EXECUTABLE} -agentlib:${AGENT_NAME}="${agent_options},abrt=$$ABRT_ENABLED,output=${target_name}.log" ${java_params}
         DEPENDS AbrtChecker ${depends}
         WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
diff --git a/test/RemoteTest.java b/test/RemoteTest.java
index 6071f8e..040384f 100644
--- a/test/RemoteTest.java
+++ b/test/RemoteTest.java
@@ -73,11 +73,19 @@ public class RemoteTest {
         server.setExecutor(null); // creates a default executor
         server.start();
 
+        /* Download the jar in order to fully intialize the second thread.
+         * Since Java-1.8 HttpExchange.sendResponseHeaders() adds 'Date' header
+         * with value formated according to locale. Getting the locale leads to
+         * loading of some other class which results in a deadlock.
+         */
+        URL remoteJarUrl = new URL("http://localhost:54321/JarTest.jar");
+        InputStream input = remoteJarUrl.openStream();
+        input.close();
+
         try {
             Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
             method.setAccessible(true);
-            method.invoke(ClassLoader.getSystemClassLoader(), new Object[]{new URL("http://localhost:54321/JarTest.jar")});
-
+            method.invoke(ClassLoader.getSystemClassLoader(), new Object[]{remoteJarUrl});
             /* Loaded these classes into cache. */
             final String needed[] = {"SimpleTest", "ThreadUncaughtException", "ThreadCaughtException"};
             for (String requiredClass : needed) {
diff --git a/test/outputs/run_remote.log.in b/test/outputs/run_remote.log.in
index 90f5db7..aeb7890 100644
--- a/test/outputs/run_remote.log.in
+++ b/test/outputs/run_remote.log.in
@@ -7,7 +7,7 @@ Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 42
 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/sun/reflect/NativeMethodAccessorImpl.class]
 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/sun/reflect/DelegatingMethodAccessorImpl.class]
 	at java.lang.reflect.Method.invoke(Method.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/java/lang/reflect/Method.class]
-	at RemoteTest.main(RemoteTest.java:102) [file:@CMAKE_BINARY_DIR@/test/RemoteTest.class]
+	at RemoteTest.main(RemoteTest.java:110) [file:@CMAKE_BINARY_DIR@/test/RemoteTest.class]
 executable: @CMAKE_BINARY_DIR@/test/RemoteTest.class
 Uncaught exception java.lang.NullPointerException in method SimpleTest.throwNullPointerException()
 Exception in thread "main" java.lang.NullPointerException
@@ -17,5 +17,5 @@ Exception in thread "main" java.lang.NullPointerException
 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/sun/reflect/NativeMethodAccessorImpl.class]
 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/sun/reflect/DelegatingMethodAccessorImpl.class]
 	at java.lang.reflect.Method.invoke(Method.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/java/lang/reflect/Method.class]
-	at RemoteTest.main(RemoteTest.java:104) [file:@CMAKE_BINARY_DIR@/test/RemoteTest.class]
+	at RemoteTest.main(RemoteTest.java:112) [file:@CMAKE_BINARY_DIR@/test/RemoteTest.class]
 executable: @CMAKE_BINARY_DIR@/test/RemoteTest.class
-- 
1.8.3.1