tiles-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric B <ebe...@hotmail.com>
Subject Re: OptionsRenderer not working
Date Mon, 28 Oct 2013 14:20:39 GMT
On 13-10-28 9:28 AM, Mick Semb Wever wrote:
> ClamAV 0.96.5
>
>
>> I've traced this back to the
>> org.springframework.web.servlet.view.tiles3.SpringWildcardServletTilesApplicationContext.getResources(String)
>
>
> Please remove SpringWildcardServletTilesApplicationContext from your
> spring xml.
>
>
> SpringWildcardServletTilesApplicationContext comes automatically from TilesConfigurer
>   ref: https://github.com/spring-projects/spring-framework/commit/42a9285
>
>
>
>> or there is a bug in OptionsRenderer that doesn't properly handle the
>> IllegalArgumentException
>
> It would help to see the stack trace to this IAE.
> But the OptionsRenderer does not fallback when there's an exception in a
> template (jsp) that it has found. In this situation that template is
> broken and the exception is thrown. OptionsRenderer only falls back when
> a template is not found.

I've removed the SpringWildcardServletTilesApplicationContext from the config file, but it
does not make a difference.  The problem that I've found is 
the following code in the SpringWildcardServletTilesAppContext file.  Lines 78-99.  getResources(String):

	public Collection<ApplicationResource> getResources(String path) {
		Resource[] resources;
		try {
			resources = resolver.getResources(path);
		} catch (IOException e) {
			return Collections.<ApplicationResource> emptyList();
		}
		Collection<ApplicationResource> resourceList = new ArrayList<ApplicationResource>();
		if (resources != null && resources.length > 0) {
			for (int i = 0; i < resources.length; i++) {
				URL url;
				try {
					url = resources[i].getURL();
					resourceList.add(new URLApplicationResource(url.toExternalForm(), url));
				} catch (IOException e) {
					// shouldn't happen with the kind of resources we're using
					throw new IllegalArgumentException("no URL for " + resources[i].toString(), e);
				}
			}
		}
		return resourceList;
	}


The OptionsRenderer calls on this method in renderAttempt() at line 124:
                 if (null != applicationContext.getResource(template)) { // can throw FileNotFoundException
!

But if you read the code, you see that FileNotFound is actually never thrown.  Since FileNotFoundException
is a subclass of IOException, the exception 
is caught and wrapped in an IllegalArgumentException, which is a runtime exception.  renderAttempt()
only tries to catch FileNotFound exceptions, 
which are never actually thrown, and consequently, it is never able to process the different
options.

A fix should be fairly easy (although a little ugly) in OptionsRenderer.renderAttempt(). 
It would be to catch the IllegalArgumentException, and see 
if the cause is a FileNotFound exception.  Alternatively, it would be to modify the SpringWildcardServletTilesApplicationContext.getResources()
method 
to allow throwing of the raw exception and not just the wrapped RuntimeException.

I tried to look through GitHub histroy on the SpringWildcard file, but see that the getResources()
method has always had the same logic in it.  But 
the history is fairly short.  I presume it was merged/created from something else, but don't
know what the predecessor was so it is difficult for me 
to look and see if this logic changed at somepoint, thereby breaking your OptionsRenderer
class.

Thanks,

Eric


Thanks,

Eric


Mime
View raw message