From e8b160a938556376457332dad418ccd0df590b2b Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 21 Aug 2014 07:28:35 +0200 Subject: [PATCH] PR 56873 make sure connection is established when reading last modified --- WHATSNEW | 5 +++++ .../apache/tools/ant/types/resources/URLResource.java | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/WHATSNEW b/WHATSNEW index 5894c07c7..36b98806b 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -27,6 +27,11 @@ Fixed bugs: cannot determine the local hostname. Bugzilla Report 56593 + * URLResource#getLastModified tried to access the connection to the + URL without making sure it was established, potentially leading to + a NullPointerException. + Bugzilla Report 56873 + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/types/resources/URLResource.java b/src/main/org/apache/tools/ant/types/resources/URLResource.java index 3ad1bd179..ab564ca62 100644 --- a/src/main/org/apache/tools/ant/types/resources/URLResource.java +++ b/src/main/org/apache/tools/ant/types/resources/URLResource.java @@ -265,7 +265,14 @@ public class URLResource extends Resource implements URLProvider { if (!isExists(false)) { return 0L; } - return conn.getLastModified(); + try { + connect(); + long lastModified = conn.getLastModified(); + close(); + return lastModified; + } catch (IOException e) { + return UNKNOWN_DATETIME; + } } /**