Return-Path: Delivered-To: apmail-incubator-harmony-commits-archive@www.apache.org Received: (qmail 26782 invoked from network); 24 Mar 2006 13:43:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 24 Mar 2006 13:43:43 -0000 Received: (qmail 28069 invoked by uid 500); 24 Mar 2006 13:43:43 -0000 Delivered-To: apmail-incubator-harmony-commits-archive@incubator.apache.org Received: (qmail 28037 invoked by uid 500); 24 Mar 2006 13:43:43 -0000 Mailing-List: contact harmony-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-commits@incubator.apache.org Received: (qmail 28023 invoked by uid 99); 24 Mar 2006 13:43:43 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Mar 2006 05:43:42 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [192.87.106.226] (HELO ajax.apache.org) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Mar 2006 05:43:42 -0800 Received: from ajax (localhost.localdomain [127.0.0.1]) by ajax.apache.org (Postfix) with ESMTP id 2E8E7D49FC for ; Fri, 24 Mar 2006 13:43:21 +0000 (GMT) Message-ID: <582938432.1143207801112.JavaMail.jira@ajax> Date: Fri, 24 Mar 2006 13:43:21 +0000 (GMT) From: "Anton Luht (JIRA)" To: harmony-commits@incubator.apache.org Subject: [jira] Created: (HARMONY-246) java.nio.channels.FileChannel.tryLock() should be non-blocking MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N java.nio.channels.FileChannel.tryLock() should be non-blocking -------------------------------------------------------------- Key: HARMONY-246 URL: http://issues.apache.org/jira/browse/HARMONY-246 Project: Harmony Type: Bug Components: Classlib Environment: Windows, Linux Reporter: Anton Luht j2se 1.4.2 spec for java.nio.channels.FileChannel says: tryLock(..) Attempts to acquire a lock on the given region of this channel's file. This method does not block. An invocation of this always returns immediately, either having acquired a lock on the requested region or having failed to do so. If it fails to acquire a lock because an overlapping lock is held by another program then it returns null. If it fails to acquire a lock for any other reason then an appropriate exception is thrown. in Harmony code this method blocks Suggested fix (naive): always use O_NONBLOCK in fcntl Code to reproduce: import java.io.*; public class Test { public static void main(String args[]) throws Exception { File f = new File("abcd"); f.deleteOnExit(); new FileOutputStream(f, true).getChannel().tryLock(); System.err.println("locked OK"); String javaCmd = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; if(args.length == 0) { Process p = Runtime.getRuntime().exec(new String[] { javaCmd, "-cp", System.getProperty("java.class.path"), "Test", "foo" } ); String line; InputStream is = p.getInputStream(); BufferedReader input = new BufferedReader(new InputStreamReader(p .getErrorStream())); while ((line = input.readLine()) != null) { System.err.println("Child prints: " + line); } input.close(); } } } Steps to reproduce: 1. Build Harmony j2se subset as described in README.txt. 2. Compile Test.java using BEA 1.4 javac > javac Test.java 3. Run java using compatible VM (J9) > java Test Output : java version "1.4.2_04" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32, Native Threads, GC strategy: parallel) locked OK Child prints: locked OK Output in Harmony: locked OK JUnit test: ---------------FileLockTest.java------------ import java.io.*; import junit.framework.*; public class FileLockTest extends TestCase { static boolean childVM = false; public static void main(String[] args) { childVM = args.length > 0; junit.textui.TestRunner.run(FileLockTest.class); } public void testFileLock() throws Exception { File f = new File("abcd"); f.deleteOnExit(); new FileOutputStream(f, true).getChannel().tryLock(); System.err.println("locked OK"); String javaCmd = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; if (!childVM) { Process p = Runtime.getRuntime().exec( new String[] { javaCmd, "-cp", System.getProperty("java.class.path"), this.getClass().getName(), "foo" }); String line; BufferedReader input = new BufferedReader(new InputStreamReader(p .getErrorStream())); while ((line = input.readLine()) != null) { System.err.println("Child prints: " + line); } input.close(); } } } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira