-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Mark,

On 7/16/13 7:47 PM, Mark Eggers wrote:
>> For a JAR file, I use the following code (don't shoot me - I'm
>> an admin / architect, not a developer).

This may be part of the problem. Don't feel bad: you just need a
developer in this case to bail you out.

> Mark, thanks for pointing out (gently) to RTFJD. While
> JarURLConnection does not have a close method, JarFile certainly
> does. As well as I should be checking the return value from
> JarURLConnection.getJarFile . . .
> 
> Taking those two thoughts in mind, a more correct (still ugly, but
> it works) method might be:
> 
> public ArrayList<String> getResources(String resourcePath, String
> ending) { Pattern p = Pattern.compile("^" + resourcePath + "/.+(" +
> ending + ")$"); try { JarURLConnection urlCon = (JarURLConnection)
> url.openConnection(); urlCon.setUseCaches(false); JarFile jar =
> urlCon.getJarFile(); if (null != jar) { Enumeration<JarEntry> je =
> jar.entries(); while (je.hasMoreElements()) { String entry =
> je.nextElement().getName(); if (log.isDebugEnabled()) { 
> log.debug("JAR entry: " + entry); } Matcher m = p.matcher(entry); 
> if (m.matches()) { resources.add(entry); } } jar.close();

You definitely want to clean-up your resources in your "finally"
block. That requires you to declare them before the "try" and then
test for null in the finally. But it's much safer: if a
RuntimeException gets thrown in your try block, you will not close the
JAR file unless you move the "close" to the finally block.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJR5rGOAAoJEBzwKT+lPKRYzUUP/1ixwHilpyqKFNHFp9NQVWI2
AakLMsOixPrhQO9MO4AZ+lhXLuDPE8PkbmcGnSercmfHH9Fi2OnhTjnNNzAteeNQ
8y/hTRNRh4FPz3rrW6KoF28JEzGZ+xr+5JhXm+Td0pkqNA/rl5byoyN94NoEfOWb
P1Un2B4j44qI+6L4s7WeFvmj+FoRPZQHBevkbyZpB0UigT8Wp2W2bD7TIX0ZGeTc
4WCt8BEKjq+7uL8MP2IoWqS7JdsDIEa6DldJSTQPVhkEYAQkgZL86i6cEkyzJSEo
ZWvOiYw97UVzuGrm/Styn9XZ31OMDNWpDAs9/L01VQj6nOHnjsFamGGykGIqeFAp
1iPXeIGWH9qmfwDKjDifdzXMI0+qfthmkmLnQBpq3ICJzplUTjTmv4UBwQYcLBdO
xCyRuYfHqvaLN8azpf7+At/7zWV66UCQogN74abz4g1Uwv+aWV8YrvU1Dj8JBs6b
KfIxgaCa4SzuiPLvLmE0Yld4NKTZZAu/SOB1EJisR/2RKJKtROsSA307ocrttBBQ
vPV2hjn1kYjGueLxCXLG+N807pHbFdoCuJ72r28NrK+pFNnD3gVxjbINvlvCn1Zz
JxebAffObdXD0UdnyHUSjCXek6SXwsS/j8auzfMEZkRYEZlRTxnlH+RGt7hZ1SP6
e1uuQ05Iw5zsCerxcYro
=FzeN
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to