You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Mark Roth <Ma...@Sun.COM> on 2004/10/02 05:14:37 UTC

[Configuration] autoSave causing FileNotFoundException

I believe I've found a bug.  When trying to use autoSave, 
jakarta-commons-configuration gives me the following error:

-----
java.io.FileNotFoundException: file:/tmp/test.xml (No such file or 
directory)
	at java.io.FileOutputStream.open(Native Method)
	at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
	at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
	at 
org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:259)
	at 
org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:216)
	at 
org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:200)
	at 
org.apache.commons.configuration.XMLConfiguration.possiblySave(XMLConfiguration.java:566)
	at 
org.apache.commons.configuration.XMLConfiguration.clearProperty(XMLConfiguration.java:489)
	at 
org.apache.commons.configuration.AbstractConfiguration.setProperty(AbstractConfiguration.java:318)
	at 
org.apache.commons.configuration.XMLConfiguration.setProperty(XMLConfiguration.java:371)
	at test.Main.main(Main.java:22)
-----

For some reason, it converted my File into a URL but then tries to 
access it as a File path again when trying to persist my settings.

Here is a simple test application to reproduce the problem:

-----
package test;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import org.apache.commons.configuration.XMLConfiguration;

/**
  * Illustrates a bug in jakarta-commons-configuration
  *
  * @author Mark Roth
  */
public class Main {

     public static void main(String[] args)
         throws Exception
     {
         File configFile = new File("/tmp/test.xml");
         createSampleTestXml(configFile);
         XMLConfiguration config = new XMLConfiguration(configFile);
         config.setAutoSave(true);
         config.setProperty("a", "b");
     }

     private static void createSampleTestXml(File f)
         throws Exception
     {
         PrintWriter out = new PrintWriter(new FileWriter(f));
         out.println("<root>");
         out.println("  test");
         out.println("</root>");
         out.close();
     }
}
-----

Is this a known error?  Any known workarounds?

Thanks,
---
Mark Roth, Staff Engineer, Java Software
JSP 2.0 / 2.1 Specification Lead
Java Enterprise Community Leader
http://community.java.net/java-enterprise
Sun Microsystems, Inc.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [Configuration] autoSave causing FileNotFoundException

Posted by Emmanuel Bourg <sm...@lfjr.net>.
Hi Mark, thank you for reporting this issue, I just checked in a fix. 
Let us know how it works for you.

Emmanuel Bourg


Mark Roth wrote:

> I believe I've found a bug.  When trying to use autoSave, 
> jakarta-commons-configuration gives me the following error:
> 
> -----
> java.io.FileNotFoundException: file:/tmp/test.xml (No such file or 
> directory)
>     at java.io.FileOutputStream.open(Native Method)
>     at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
>     at java.io.FileOutputStream.<init>(FileOutputStream.java:131)

> 
> Is this a known error?  Any known workarounds?
> 
> Thanks,
> ---
> Mark Roth, Staff Engineer, Java Software
> JSP 2.0 / 2.1 Specification Lead
> Java Enterprise Community Leader
> http://community.java.net/java-enterprise
> Sun Microsystems, Inc.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org