JIRA

  • Log In Access more options
    • Online Help
    • GreenHopper Help
    • Agile Answers
    • Use Agile By Default
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Agile Access more options (Alt+g)
  • Create Issue
  • Mule
  • MULE-1112

Paths relative to user.dir not working properly (workaround for a Sun JDK bug)

  • Agile Board
  • More Actions
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.3
  • Fix Version/s: 1.3.2
  • Component/s: Core: (other)
  • Labels:
    None
  • Environment:

    Windows XP, jdk 1.5.0_08

  • Similar Issues:
    None

Description

Using mule 1.3 final we are unable to properly set relative paths in mule endpoints due a strange behavior in how they are handled when the user.dir property is set "manually".

Background: due to the changes in the following commit paths are now resolved as relative to the "user.dir" system property; user.dir is automatically set by the service wrapper when mule is run as a server:

http://fisheye.codehaus.org/browse/mule/trunk/mule/core/src/main/java/org/mule/util/FileUtils.java#r2970

In our case mule is embedded in an existing spring application, loaded as a webapp. Since we need to use relative paths in the configuration we set the user.dir to be the webapp root before loading muleManager calling "System.setProperty("user.dir", root)" directly.
Unfortunately this doesn't make mule resolving paths relative to the new dir: various methods in java.io.File seems to resolve relative paths using the original user.dir if File.getCanonicalFile() is not called and this causes a very strange behavior in Mule.

For example this is what happens on the FileUtils.openDirectory(String directory) method, assuming:

  • original user.dir set to "/user1"
  • user.dir set using System.setProperty: "/user2"

public static File openDirectory(String directory) throws IOException
{

// here directory is "test"

File dir = new File(directory);

// dir.getAbsolutePath() returns "/user2/test" : ok

if (!dir.exists()) // dir.exists returns false..
// we found that this strangely looks for "/user1/test" also if the user.dir is now set to user2

{ dir.mkdirs(); // directories are created at "/user2/test" : ok }

if (!dir.isDirectory() || !dir.canRead())
// dir1 doesn't exist since isDirectory() looks for "/user1/test" while mkdirs created the correct "/user2/test" dir

{ throw new IOException("Path: " + directory + " exists but isn't a directory"); // exception is thrown }

... so the new user.dir is used when calling mkdirs(), while the original user dir is used when calling exists(), isDirectory() or canRead(). If the file is obtained using dir.getCanonicalFile() everything work as expected. After changing the first line in the method to:
File dir = new File(directory).getCanonicalFile();
the directory gets always resolved to the same user.dir.

In order to make Mule properly handle relative paths we had to add a getCanonicalFile() call in various mule classes (not sure if could be needed in some more class, this is what we had to fix in order to make our application work):
org.mule.util.FileUtils
org.mule.providers.file.FileMessageAdapter
org.mule.providers.file.FileMessageReceiver
org.mule.providers.file.transformers.FileToByteArray

I am not sure about the cause of this strange behavior in java.io.File, anybody else ever tried to set "user.dir" after the JVM startup? Do anybody see any problem in fixing the above methods/classes as described? I could supply a patch if needed, I would really like to be able to use relative paths without patching Mule 1.3.1 too

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. File
    MULE-1112.diff
    15/Oct/06 01:52 PM
    10 kB
    Fabrizio Giustina

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
  • Transitions
  • Commits
  • Source
  • Builds
Hide
Permalink
Fabrizio Giustina added a comment - 11/Oct/06 11:47 AM

just found out that this is due to a bug already traced in the sun bug database:

http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4117557

Work Arounds:

  • Do not use relatively directory.
  • use the following when creating a file:
    File dummy = new File("relativeFileName");
    File realFile = new File(dummy.getAbsolutePath());
Show
Fabrizio Giustina added a comment - 11/Oct/06 11:47 AM just found out that this is due to a bug already traced in the sun bug database: http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4117557 Work Arounds:
  • Do not use relatively directory.
  • use the following when creating a file: File dummy = new File("relativeFileName"); File realFile = new File(dummy.getAbsolutePath());
Hide
Permalink
Andrew Perepelytsya added a comment - 11/Oct/06 12:07 PM

Fabrizio, many thanks for digging it up and testing the workaround, we'll apply it shortly so it comes in 1.3.1.

Regarding getAbsolutePath()/getCanonicalPath() , the preferred call is the getCanonicalPath(), as it resolves a number corner cases pertinent to Solaris and other unix flavours. It has been reported to generally run slower than the getAbsolutePath(), but nothing major for Mule, I hope.

Show
Andrew Perepelytsya added a comment - 11/Oct/06 12:07 PM Fabrizio, many thanks for digging it up and testing the workaround, we'll apply it shortly so it comes in 1.3.1. Regarding getAbsolutePath()/getCanonicalPath() , the preferred call is the getCanonicalPath(), as it resolves a number corner cases pertinent to Solaris and other unix flavours. It has been reported to generally run slower than the getAbsolutePath(), but nothing major for Mule, I hope.
Hide
Permalink
Fabrizio Giustina added a comment - 15/Oct/06 01:52 PM

patch against current trunk: this should hopefully fix any recurrence where new File() is called passing a relative path as argument. getCanonicalFile() is used everywhere, except for methods that were not expecting IOExceptions (for which I used getAbsolutePath(), in order to avoid throwing or swallowing new checked exceptions).
All the existing testcases continue to work properly (no specific testcases added, this look pretty difficult to test since it requires using/manipulating existing system properties).

Show
Fabrizio Giustina added a comment - 15/Oct/06 01:52 PM patch against current trunk: this should hopefully fix any recurrence where new File() is called passing a relative path as argument. getCanonicalFile() is used everywhere, except for methods that were not expecting IOExceptions (for which I used getAbsolutePath(), in order to avoid throwing or swallowing new checked exceptions). All the existing testcases continue to work properly (no specific testcases added, this look pretty difficult to test since it requires using/manipulating existing system properties).
Hide
Permalink
Fabrizio Giustina added a comment - 18/Nov/06 10:48 AM

<ping> sorry to bother, but could anybody commit this patch before the 1.3.1 release as previously discussed? Could be a very annoying problem for users that run mule embedded in another application...

Show
Fabrizio Giustina added a comment - 18/Nov/06 10:48 AM <ping> sorry to bother, but could anybody commit this patch before the 1.3.1 release as previously discussed? Could be a very annoying problem for users that run mule embedded in another application...
Hide
Permalink
Andrew Perepelytsya added a comment - 18/Nov/06 07:15 PM

There's a bit more than the patch, but the idea is clear. Created a factory method for java.io.File constructor calls in production classes (tests don't need this fix).

http://fisheye.codehaus.org/changelog/mule/?cs=3927

Show
Andrew Perepelytsya added a comment - 18/Nov/06 07:15 PM There's a bit more than the patch, but the idea is clear. Created a factory method for java.io.File constructor calls in production classes (tests don't need this fix). http://fisheye.codehaus.org/changelog/mule/?cs=3927

People

  • Assignee:
    Andrew Perepelytsya
    Reporter:
    Fabrizio Giustina
Vote (0)
Watch (0)

Dates

  • Created:
    11/Oct/06 11:41 AM
    Updated:
    17/Sep/08 09:50 PM
    Resolved:
    18/Nov/06 07:15 PM

Agile

  • View on Board
  • Atlassian JIRA (v5.0.7#734-sha1:8ad78a6)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for MuleForge. Try JIRA - bug tracking software for your team.