You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by qi...@apache.org on 2008/10/30 09:40:52 UTC
svn commit: r709116 - in /harmony/enhanced/classlib/trunk:
modules/luni/src/main/java/org/apache/harmony/luni/internal/process/
modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/process/
support/src/test/java/tests/support/
Author: qiuxx
Date: Thu Oct 30 01:40:51 2008
New Revision: 709116
URL: http://svn.apache.org/viewvc?rev=709116&view=rev
Log:
Apply for HARMONY-6004,([classlib] [luni] System.exec() gets interruption will cause InternalError)
Added:
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/process/
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/process/SystemProcessTest.java (with props)
Modified:
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/process/SystemProcess.java
harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Exec.java
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/process/SystemProcess.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/process/SystemProcess.java?rev=709116&r1=709115&r2=709116&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/process/SystemProcess.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/process/SystemProcess.java Thu Oct 30 01:40:51 2008
@@ -73,7 +73,7 @@
final SystemProcess p = new SystemProcess();
- p.lock = new Lock();
+ p.lock = new Object();
Runnable waitingThread = new Runnable() {
public void run() {
@@ -104,9 +104,7 @@
synchronized (p.lock) {
p.closeImpl();
p.handle = -1;
- }
- p.exitCodeAvailable = true;
- synchronized (p.lock) {
+ p.exitCodeAvailable = true;
try {
p.in.close();
} catch (IOException e) {
@@ -119,25 +117,29 @@
wait.setDaemon(true);
wait.start();
- try {
- synchronized (p.lock) {
- while (!p.waiterStarted) {
+ synchronized (p.lock) {
+ boolean interrupted = false;
+ while (!p.waiterStarted) {
+ try {
p.lock.wait();
+ } catch (InterruptedException e) {
+ interrupted = true;
}
- if (p.exception != null) {
- /* Re-throw exception that originated in the helper thread */
- p.exception.fillInStackTrace();
- if (p.exception instanceof IOException) {
- throw (IOException) p.exception;
- } else if (p.exception instanceof Error) {
- throw (Error) p.exception;
- } else {
- throw (RuntimeException) p.exception;
- }
+ }
+ if (interrupted) {
+ Thread.currentThread().interrupt();
+ }
+ if (p.exception != null) {
+ /* Re-throw exception that originated in the helper thread */
+ p.exception.fillInStackTrace();
+ if (p.exception instanceof IOException) {
+ throw (IOException) p.exception;
+ } else if (p.exception instanceof Error) {
+ throw (Error) p.exception;
+ } else {
+ throw (RuntimeException) p.exception;
}
}
- } catch (InterruptedException e) {
- throw new InternalError();
}
return p;
Added: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/process/SystemProcessTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/process/SystemProcessTest.java?rev=709116&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/process/SystemProcessTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/process/SystemProcessTest.java Thu Oct 30 01:40:51 2008
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.luni.tests.internal.process;
+
+import java.io.OutputStream;
+
+import junit.framework.TestCase;
+import tests.support.Support_Exec;
+
+public class SystemProcessTest extends TestCase {
+
+ public void test_interrupt() throws Exception {
+ Object[] execArgs = null;
+ Process process = null;
+ try {
+ Thread.currentThread().interrupt();
+ execArgs = Support_Exec.execJava2(
+ new String[] { "tests.support.Support_AvailTest" }, null,
+ true);
+ process = (Process) execArgs[0];
+ OutputStream os = process.getOutputStream();
+ os.write("10 5 abcde".getBytes());
+ os.close();
+ process.waitFor();
+ fail("Should throw InterruptedException");
+ } catch (InterruptedException e) {
+ // Expected
+ }
+
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // Ignored
+ }
+ process.waitFor();
+ Support_Exec.checkStderr(execArgs);
+ process.destroy();
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/process/SystemProcessTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Exec.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Exec.java?rev=709116&r1=709115&r2=709116&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Exec.java (original)
+++ harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Exec.java Thu Oct 30 01:40:51 2008
@@ -193,7 +193,21 @@
synchronized (proc) {
errThread.start();
// wait for errThread to start
- proc.wait();
+ int count = 0;
+ boolean isFinished = false;
+ while(!isFinished) {
+ try {
+ proc.wait();
+ isFinished = true;
+ } catch (InterruptedException e) {
+ if(++count == 2) {
+ throw e;
+ }
+ }
+ }
+ if(count > 0) {
+ Thread.currentThread().interrupt();
+ }
}
return new Object[] { proc, errBuf };