Issue2131

classification
Title: bug in os.path.exists
Type: crash Severity: normal
Components: Versions: Jython 2.7
Milestone:
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: Nosy List: aryeh, zyasoft
Priority: Keywords:

Created on 2014-04-24.14:25:36 by aryeh, last changed 2014-06-30.17:47:36 by zyasoft.

Files
File name Uploaded Description Edit Remove
path_exists_bug.py aryeh, 2014-04-24.14:25:35
Messages
msg8305 (view) Author: (aryeh) Date: 2014-04-24.14:25:35
The attached script produces an error which I reported on the ImageJ mailing list.

Here is what I wrote there:

I have the following snippet in my code, designed to create an output directory if it does not already exist:

91 outDir = os.path.join(inputDir,"zPlots/")
92 print outDir
93 if not os.path.exists(outDir):
94     os.makedirs(outDir)


If the directory exists, this runs ok. If I skip line 93 and make the directory withotu checking,

If the directory does not exist, it produces an error.

File "<iostream>", line 93, in <module>
File "/Applications/local/fiji/Fiji.app/jars/jython-2.7-bl.jar /Lib/posixpath.py", line 171, in exists
File "/Applications/local/fiji/Fiji.app/jars/jython-2.7-bl.jar /Lib/posixpath.py", line 171, in exists
java.lang.AbstractMethodError: org.python.modules.posix.PythonPOSIXHandler.error(Ljnr/constants/platform/Errno;Ljava/lang/String;)V
    at jnr.posix.BaseNativePOSIX.stat(BaseNativePOSIX.java:309)

There is these a long list of at jnr.posix ... and org.posix.... etc , which I have not copied.
(BTW -- is there a way to copy the text from the error display of the Fiji script editor?)

I also tried

outDir = inputDir + "zPlots/"

with the same problem.

I tried also to use try and except on this.
except AbstractMethodError seems to catch this.
I suppose I could catch any failure and assume that the directory exists, but this does not seem the correct
way to do this.
msg8498 (view) Author: Jim Baker (zyasoft) Date: 2014-05-21.23:12:43
Maybe a SecurityManager problem? Jython has significantly reduced functionality for interacting with the underlying OS without full Java Native Runtime (JNR) support.

Ideally we could have a test that reproduces the issue that doesn't depend on ImageJ.
msg8836 (view) Author: Jim Baker (zyasoft) Date: 2014-06-28.04:04:13
Closing this out as not able to reproduce - os.path.exists is widely used by Jython code, there must be something else going on, like a SecurityManager or other problem.

One possible workaround: http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#exists(java.nio.file.Path,%20java.nio.file.LinkOption...)
msg8845 (view) Author: (aryeh) Date: 2014-06-29.06:46:04
On 6/28/14, 7:04 AM, Jim Baker wrote:
> Jim Baker added the comment:
>
> Closing this out as not able to reproduce - os.path.exists is widely used by Jython code, there must be something else going on, like a SecurityManager or other problem.
>
> One possible workaround: http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#exists(java.nio.file.Path,%20java.nio.file.LinkOption...)
>
> ----------
> resolution:  -> invalid
> status: open -> pending
>
>

This turned out to be a problem in Fiji (ImageJ). There was a conflict 
with the ruby interpreter, which have since been resolved.

Best regards
--aryeh

-- 
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051
msg8853 (view) Author: Jim Baker (zyasoft) Date: 2014-06-30.17:47:36
Aryeh, thanks for finding the actual problem!
History
Date User Action Args
2014-06-30 17:47:36zyasoftsetstatus: pending -> closed
messages: + msg8853
2014-06-29 06:46:05aryehsetmessages: + msg8845
2014-06-28 04:04:13zyasoftsetstatus: open -> pending
resolution: invalid
messages: + msg8836
2014-05-21 23:12:43zyasoftsetnosy: + zyasoft
messages: + msg8498
2014-04-24 14:25:36aryehcreate