Am 12.05.2010 22:36, schrieb arja srinivasu:
Thanks for the response, Sorry for the trouble, it seems the email is not
displaying the source code properly when copying the formatted code from
eclipse: trying this again, after copying it from notepad, I only saw this
mailing list that I send an email to, Is there a way that I can post the
response online.
private static void load(String dataFilePath)
throws Exception
{
URL dataFileURL = null;
HierarchicalConfiguration dataFromFile = null;
final File dataFile = new File(dataFilePath);
assertTrue(dataFile.exists(), "Data file does not exist: " + dataFile);
log.info("Reading the data file: " + dataFile);
dataFileURL = ConfigurationUtils.locate(dataFilePath);
log.info(dataFileURL.toString());
dataFromFile = new XMLConfiguration(dataFile);
}
Here is the url that is printed:
2010-05-12 13:23:11,266 INFO c.v.v.e.TestExecutionUtils [load:382] [main] -
file:/G:/testware/events.verification.xml
Yes I tried it with a file, I think I am getting the same error with the same
root cause with the stack trace as below even when I construct the
XMLConfiguration passing a File object.
2010-05-12 13:23:11,297 ERROR c.v.v.e.DataDrivenTestFactory
[createDataDrivenTests:89] [main] - Unable to load the configuration file
events.verification.dvs.xmlorg.apache.commons.configuration.ConfigurationException
at org.apache.commons.configuration.AbstractFileConfiguration.load(
at org.apache.commons.configuration.AbstractFileConfiguration.load(
at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.load(
at
org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.<init>(
at org.apache.commons.configuration.XMLConfiguration.<init>(: Unable to load
the configuration file events.verification.dvs.xmlAbstractFileConfiguration.java:227)
[commons-configuration-1.6.jar:1.6]AbstractFileConfiguration.java:197)
[commons-configuration-1.6.jar:1.6]AbstractHierarchicalFileConfiguration.java:164)
[commons-configuration-1.6.jar:1.6]AbstractHierarchicalFileConfiguration.java:109)
[commons-configuration-1.6.jar:1.6]XMLConfiguration.java:255)
[commons-configuration-1.6.jar:1.6]Caused by:
at java.net.URLDecoder.decode(
at java.net.URLDecoder.decode(
at org.apache.commons.configuration.ConfigurationUtils.fileFromURL(
at org.apache.commons.configuration.AbstractFileConfiguration.load(
at org.apache.commons.configuration.AbstractFileConfiguration.load(
... 8 common frames omittedjava.lang.NullPointerException:
nullURLDecoder.java:123) [na:1.6.0_18]URLDecoder.java:83)
[na:1.6.0_18]ConfigurationUtils.java:719)
[commons-configuration-1.6.jar:1.6]AbstractFileConfiguration.java:276)
[commons-configuration-1.6.jar:1.6]AbstractFileConfiguration.java:219)
[commons-configuration-1.6.jar:1.6]
Thanks
Srinu
Unfortunately the stack trace is also pretty unreadable.
I would recommend to change your load() method so that it creates the
XMLConfiguration directly from the file. The manual conversion is
pointless because this is done internally as required. If you then
receive an exception, please post the stack trace.
What makes me wonder is the fact that the URL you printed does not seem
to be any special. Therefore I do not believe that the problem lies
within Commons Configuration: Reading a configuration file is the most
basic use case; if this did not work, we would receive lots of bug reports.
Oliver
----- Original Message ----
From: Oliver Heger<[email protected]>
To: Commons Users List<[email protected]>
Sent: Wed, May 12, 2010 12:40:28 PM
Subject: Re: Null pointer exception while creating a XMLConfiguration object in
a static method.
Am 11.05.2010 21:47, schrieb arja srinivasu:
Thanks for the response, Here is the code again, hope this time it does not
appear garbled.
{
URL dataFileURL =
HierarchicalConfiguration dataFromFile =
assertTrue(dataFile.exists(), privatestatic void load(String
dataFilePath)throwsExceptionnull;null;finalFile dataFile =
newFile(dataFilePath);"Data file does not exist: "+ dataFile);dataFileURL =
ConfigurationUtils.locate(dataFilePath);
//The line below throws the error.
dataFromFile =
}
Thankslog.info("Reading the data file: "+
dataFile);newXMLConfiguration(dataFileURL);
Srinu
I still cannot read the source code, but anyway:
Because the exception happens in URLDecoder the URL returned by
ConfigurationUtils seems to be strange. Can you print it out to check
how it actually looks like?
I am not sure why you do the file to URL conversion at all. You can
directly create the XMLConfiguration passing your File object to the
constructor. Did you test this?
Oliver
----- Original Message ----
From: Oliver Heger<[email protected]>
To: Commons Users List<[email protected]>
Sent: Tue, May 11, 2010 12:27:51 PM
Subject: Re: Null pointer exception while creating a XMLConfiguration object in
a static method.
Am 11.05.2010 18:50, schrieb arja srinivasu:
Hi,
I have been running into an issue while creating an xml configuration object
from an xml file, I am using jdk 1.6.0_20 and commons-configuration-1.6.jar,
similar code works when the method is non-static, appreciate any comments or
pointers in resolving this issue
Here is the code which is creating this XMLConfiguration object.
privatestatic void load(String dataFilePath)throwsExceptionnull;null; finalFile dataFile =
newFile(dataFilePath);"Data file does not exist: "+ dataFile);// this check succeeds no assertion
error is thrown"Data file is not readable: "+ dataFile);// this check succeeds no assertion error
is thrown log.info("Reading the data file: "+ dataFile);newXMLConfiguration(dataFileURL);
{
URL dataFileURL =
HierarchicalConfiguration dataFromFile =
assertTrue(dataFile.exists(),
assertTrue(dataFile.canRead(),
dataFileURL = ConfigurationUtils.locate(dataFilePath); //Returns a
proper url of the file passed.
dataFromFile =
}
Your code example got somehow messed up and is hardly readable. Can you
please repost?
Oliver
Here is a partial stack trace of the error:
java.lang.NullPointerException
at java.net.URLDecoder.decode(Unknown Source) [na:1.6.0_20]
at java.net.URLDecoder.decode(Unknown Source) [na:1.6.0_20]
at org.apache.commons.configuration.ConfigurationUtils.fileFromURL(
at org.apache.commons.configuration.AbstractFileConfiguration.load(
at org.apache.commons.configuration.AbstractFileConfiguration.load(
at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.load(
at
org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.<init>(
at org.apache.commons.configuration.XMLConfiguration.<init>(
Thanks in advance.
--Srinu: nullConfigurationUtils.java:719)
[commons-configuration-1.6.jar:1.6]AbstractFileConfiguration.java:276)
[commons-configuration-1.6.jar:1.6]AbstractFileConfiguration.java:193)
[commons-configuration-1.6.jar:1.6]AbstractHierarchicalFileConfiguration.java:164)
[commons-configuration-1.6.jar:1.6]AbstractHierarchicalFileConfiguration.java:126)
[commons-configuration-1.6.jar:1.6]XMLConfiguration.java:267)
[commons-configuration-1.6.jar:1.6]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]