Bug 51829 - URLResource.connect() logs as error when URL.openConnection() fails
Summary: URLResource.connect() logs as error when URL.openConnection() fails
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.8.2
Hardware: PC Windows XP
: P2 minor (vote)
Target Milestone: 1.8.3
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-15 19:23 UTC by rich
Modified: 2011-11-17 11:57 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description rich 2011-09-15 19:23:03 UTC
URLResource.connect() logs the IOException thrown by URL.openConnection()  (line 376 in URLResource.java for Ant 1.8.2).  Normally, this would be OK--exception I've wrapped the URL resource in a <restrict> with an <exists> selector because in my case it can be OK if the URL isn't found.

The net result is we're getting errors logged even though the build doesn't fail.

Is there really a reason to log this as an error?  Isn't the exception an indication that something might have gone wrong, but we should let the caller assume responsibility for determining if this is really an error?
Comment 1 Stephan Piesker 2011-11-11 20:28:57 UTC
Hello,

I'm just trying to understand your issue.
I created a file it can not create the issue though.
Can you give me a sample code to show, with which it does not work out for you?
Comment 2 rich 2011-11-11 21:15:21 UTC
Here's a script that demonstrates the problem:

<project>
	<import optional="true">
		<url file="foo.x" />
	</import>
</project>

When I run this I get:

C:\Development\projects\ant-playground\url-resource-error>ant
Buildfile: C:\Development\projects\ant-playground\url-resource-error\build.xml
java.io.FileNotFoundException: C:\Development\projects\ant-playground\url-resource-error\foo.x (The system cannot find the file specified)

BUILD SUCCESSFUL
Total time: 0 seconds

I made the import optional so even though the file doesn't exist the build works.  But why print out the java.io.FileNotFoundException error message?

I have users of my build script asking me that; worse, our jenkins builds flag that as some kind of critical problem.
Comment 3 Stephan Piesker 2011-11-13 19:54:25 UTC
OK, I can reproduce this issue. But I am of the opinion it is correct. <import optional="true"> means that the script should continue in the event of an error.
The manual is:
Optional | If true, do not exist stop the build if the file does not, default is false.

You want that the script will continue running in the event of an error.
It does this well and you know indicates that there is an error
when you import the file was foo.x.
The problem I see in the Tag <url>, because this would cause the error.
First, by the Tag <url> trying to open a file and the error happens there. Import realize that something went wrong and continues.
In <import> there is one attribute that file names.
Why do you use <url>?
Hereby it should work:

<project>
     <import file="foo.x" optional="true"/>
</ project>
Comment 4 rich 2011-11-14 13:44:40 UTC
This is a simplified example--I can't share the actual code--that reproduces the problem.  I'm aware of what optional on <import> means.  That's also why I use a <url> resource instead of a file attribute on <import> because the problem is with URLResource.

My complaint is only about the error message logged to the console during the build: it prints out java.io.FileNotFoundException message even though the build is fine.  The build worked, so why log this message?

My recommendation is to simply remove the log statement (or reduce its severity to DEBUG) in URLResource at line 376.
Comment 5 Stefan Bodewig 2011-11-17 11:57:13 UTC
should be less noisy with svn revision 1203160