Bug 32611 - ClassCastException from Custom Task
Summary: ClassCastException from Custom Task
Status: RESOLVED WONTFIX
Alias: None
Product: Ant
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.6.2
Hardware: PC Windows 2000
: P2 normal (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords: ErrorMessage
Depends on:
Blocks:
 
Reported: 2004-12-09 18:55 UTC by Shawn Price
Modified: 2008-02-22 12:18 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shawn Price 2004-12-09 18:55:21 UTC
We are in the process of testing upgrade from Ant 1.4 to 1.6.2.  We had 
previously developed a custom copy task that overrides Copy.doFileOperation().  
After updating the proper libraries, I attempted to run our applications 
build.  What resulted was a ClassCastException (with no message) when 
attempting to get the name of the next destination file name from fileCopyMap 
(from org.apache.tools.ant.taskdefs.Copy) using the source file name.  Due to 
restrictions on corporate proprietary info, I cannot provide all the source 
code, but the offending line is:

String destinationFile = (String)fileCopyMap.get(sourceFile);

, which generates the following lines in stack trace (reprinted):

[copy] com.ourapp.tools.ant.build.CustomCopyTask.doFileOperations
(CustomCopyTask.java.88)
[copy] org.apache.tools.ant.taskdefs.Copy.execute(Copy.java:421)
[copy] org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
...

Incidentally, I've done some troubleshooting, and found through fileCopyMap.get
(sourceFile).getClass().getName() that the type (at least as far was the 
serialization mechanism is concerned) is still java.lang.String.  Can anyone 
help me on this
Comment 1 Peter Reilly 2004-12-09 19:04:46 UTC
The internals of Copy was changed from ant 1.5 to ant 1.6
to allow a file to be copied to multiple locations.

It now stores the a String[] in fileCopyMap.

You need to do:
String[] destinationFiles = (String[])fileCopyMap.get(sourceFile)

    for (int i = 0; i < destinationFiles.length; i++) {
                    String destinationFile = destinationFiles[i];
...

If you want to use the custom task in both ant 1.5 and ant 1.6 you
need to check the type:

Object dFiles = fileCopyMap.get(sourceFile)
if (dFiles instanceof String) {
   ... 1.5 code
} else {
   ... 1.6 code
}

Sorry about the inconvience.

Marking this as an *WONTFIX*, as there is not much that
can be done to fix this.