ant ftp get nullpointerException

1)现象描述:
使用以下命令获取文件时会报java.lang.nullpointerException
<ftp action="get"
server="${ftp.server}"
userid="${ftp.user}"
password="${ftp.password}"
remotedir="${ftp.dir}"
verbose="yes"
depends="yes">
<fileset dir="${lib}">
<include name="*.jar"/>
</fileset>
</ftp>


2)问题原因追溯:
${ftp.dir} are files with creation date Feb 29 current year
Incorrect parse creation date Feb 29 current year

For java 1.5/1.6:
Example 1:
SimpleDateFormat sdf = new SimpleDateFormat("MMM d yy");
sdf.setLenient(false);
System.out.println("date=" + sdf.parse("Feb 29 12:14"));

Result:
date=null;

If doesn't use command sdf.setLenient(false) then result: date = Sun Mar 01 12:14:00 EET 1970

For java 1.4:
Result always "date=Sun Mar 01 12:14:00 EET 1970", because for java 1.4 doesn't throw error NullPointerException
File: commons-net-1.4.1\src\java\org\apache\commons\net\ftp\parser\FTPTimestampParserImpl.java

Caused in function (line 225: this.recentDateFormat.setLenient(false); ):

public void configure(FTPClientConfig config) {
....

String recentFormatString = config.getRecentDateFormatStr();
if (recentFormatString == null) { this.recentDateFormat = null; } else { this.recentDateFormat = new SimpleDateFormat(recentFormatString, dfs); this.recentDateFormat.setLenient(false); }
....
}


3)解决方法:
把ant的lib 下common-net.1.4.jar包替换为2.0的包。

https://issues.apache.org/jira/browse/NET-224?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel#issue-tabs

猜你喜欢

转载自luoqinglong.iteye.com/blog/1435063
ANT
FTP