Blame SOURCES/0050-Fix-a-deadlock-in-RemoteTest.patch

f9a98e
From 992b95828e2efe54f30d81c1418e997215ed22b5 Mon Sep 17 00:00:00 2001
f9a98e
From: Jakub Filak <jfilak@redhat.com>
f9a98e
Date: Wed, 29 Oct 2014 14:07:10 +0100
f9a98e
Subject: [PATCH] Fix a deadlock in RemoteTest
f9a98e
f9a98e
Related to #42
f9a98e
---
f9a98e
 test/CMakeLists.txt            |  1 +
f9a98e
 test/RemoteTest.java           | 12 ++++++++++--
f9a98e
 test/outputs/run_remote.log.in |  4 ++--
f9a98e
 3 files changed, 13 insertions(+), 4 deletions(-)
f9a98e
f9a98e
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
f9a98e
index 4e69049..5bb2b2d 100644
f9a98e
--- a/test/CMakeLists.txt
f9a98e
+++ b/test/CMakeLists.txt
f9a98e
@@ -106,6 +106,7 @@ function(_add_test_target target_name)
f9a98e
     add_custom_target(
f9a98e
         ${target_name}
f9a98e
         ${pre_command}
f9a98e
+# -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n + jdb -attach 8001
f9a98e
         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}
f9a98e
         DEPENDS AbrtChecker ${depends}
f9a98e
         WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
f9a98e
diff --git a/test/RemoteTest.java b/test/RemoteTest.java
f9a98e
index 6071f8e..040384f 100644
f9a98e
--- a/test/RemoteTest.java
f9a98e
+++ b/test/RemoteTest.java
f9a98e
@@ -73,11 +73,19 @@ public class RemoteTest {
f9a98e
         server.setExecutor(null); // creates a default executor
f9a98e
         server.start();
f9a98e
 
f9a98e
+        /* Download the jar in order to fully intialize the second thread.
f9a98e
+         * Since Java-1.8 HttpExchange.sendResponseHeaders() adds 'Date' header
f9a98e
+         * with value formated according to locale. Getting the locale leads to
f9a98e
+         * loading of some other class which results in a deadlock.
f9a98e
+         */
f9a98e
+        URL remoteJarUrl = new URL("http://localhost:54321/JarTest.jar");
f9a98e
+        InputStream input = remoteJarUrl.openStream();
f9a98e
+        input.close();
f9a98e
+
f9a98e
         try {
f9a98e
             Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
f9a98e
             method.setAccessible(true);
f9a98e
-            method.invoke(ClassLoader.getSystemClassLoader(), new Object[]{new URL("http://localhost:54321/JarTest.jar")});
f9a98e
-
f9a98e
+            method.invoke(ClassLoader.getSystemClassLoader(), new Object[]{remoteJarUrl});
f9a98e
             /* Loaded these classes into cache. */
f9a98e
             final String needed[] = {"SimpleTest", "ThreadUncaughtException", "ThreadCaughtException"};
f9a98e
             for (String requiredClass : needed) {
f9a98e
diff --git a/test/outputs/run_remote.log.in b/test/outputs/run_remote.log.in
f9a98e
index 90f5db7..aeb7890 100644
f9a98e
--- a/test/outputs/run_remote.log.in
f9a98e
+++ b/test/outputs/run_remote.log.in
f9a98e
@@ -7,7 +7,7 @@ Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 42
f9a98e
 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/sun/reflect/NativeMethodAccessorImpl.class]
f9a98e
 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/sun/reflect/DelegatingMethodAccessorImpl.class]
f9a98e
 	at java.lang.reflect.Method.invoke(Method.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/java/lang/reflect/Method.class]
f9a98e
-	at RemoteTest.main(RemoteTest.java:102) [file:@CMAKE_BINARY_DIR@/test/RemoteTest.class]
f9a98e
+	at RemoteTest.main(RemoteTest.java:110) [file:@CMAKE_BINARY_DIR@/test/RemoteTest.class]
f9a98e
 executable: @CMAKE_BINARY_DIR@/test/RemoteTest.class
f9a98e
 Uncaught exception java.lang.NullPointerException in method SimpleTest.throwNullPointerException()
f9a98e
 Exception in thread "main" java.lang.NullPointerException
f9a98e
@@ -17,5 +17,5 @@ Exception in thread "main" java.lang.NullPointerException
f9a98e
 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/sun/reflect/NativeMethodAccessorImpl.class]
f9a98e
 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/sun/reflect/DelegatingMethodAccessorImpl.class]
f9a98e
 	at java.lang.reflect.Method.invoke(Method.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/java/lang/reflect/Method.class]
f9a98e
-	at RemoteTest.main(RemoteTest.java:104) [file:@CMAKE_BINARY_DIR@/test/RemoteTest.class]
f9a98e
+	at RemoteTest.main(RemoteTest.java:112) [file:@CMAKE_BINARY_DIR@/test/RemoteTest.class]
f9a98e
 executable: @CMAKE_BINARY_DIR@/test/RemoteTest.class
f9a98e
-- 
f9a98e
1.8.3.1
f9a98e