Quantcast

Grails 2.2.1, 2.2.3, UrlMappings and Java 1.7

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Grails 2.2.1, 2.2.3, UrlMappings and Java 1.7

jphiloon
This post was updated on .
Runtime errors trying to run with java 1.7.0_51, so see note that upgrading to Grails 2.2.3 will take care of it.  So I did that.  Now the same errors relating to URL_MAPPINGS_HOLDER.  Is this in fact due to some failure to parse UrlMappings?  Those mappings haven't changed through several version of grails - and now they are sensitive to the java compiler?  Can that be true?  What is the cure?

Here are my UrlMappings and an excerpt of the errors

	static mappings = {
				
		"/assets/service-config" {
			controller = 'about'
			action = 'serviceConfig'
		}

		"//assets/service-config" {
			controller = 'about'
			action = 'serviceConfig'
		}

		"/$controller/$action?/$id?"{
			constraints {
				// apply constraints here
			}
		}

		"//$controller/$action?/$id?"{
			constraints {
				// apply constraints here
			}
		}

		"//file/$action/$id" {
			controller = 'file'
		}
		
		"//file/$action/$filePath/**" {
			controller = 'file'
		}
		
		"500"(view:'/error')


Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.grails.internal.URL_MAPPINGS_HOLDER': Invocation of init method failed; nested exception is java.lang.ArrayIndexOutOfBoundsException: 2
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
	at org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.doCreateBean(ReloadAwareAutowireCapableBeanFactory.java:122)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:323)
	... 60 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
	at org.codehaus.groovy.grails.web.mapping.RegexUrlMapping.compareTo(RegexUrlMapping.java:612)
	at java.util.ComparableTimSort.countRunAndMakeAscending(ComparableTimSort.java:290)
	at java.util.ComparableTimSort.sort(ComparableTimSort.java:157)
	at java.util.ComparableTimSort.sort(ComparableTimSort.java:146)
	at java.util.Arrays.sort(Arrays.java:472)
	at java.util.Collections.sort(Collections.java:155)
	at org.codehaus.groovy.grails.web.mapping.DefaultUrlMappingsHolder.sortMappings(DefaultUrlMappingsHolder.java:174)
	at org.codehaus.groovy.grails.web.mapping.DefaultUrlMappingsHolder.initialize(DefaultUrlMappingsHolder.java:97)
	at org.codehaus.groovy.grails.web.mapping.UrlMappingsHolderFactoryBean.afterPropertiesSet(UrlMappingsHolderFactoryBean.java:114)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
	... 68 more
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 2.2.1, 2.2.3 and Java 1.7

jphiloon
To answer my own question, should anyone else run into this.  For some reason lost to me now, I have these entries in UrlMappings:

		"/assets/service-config" {
			controller = 'about'
			action = 'serviceConfig'
		}

		"//assets/service-config" {
			controller = 'about'
			action = 'serviceConfig'
		}

I don't recall why the second item, with double "//" characters exists.  Regardless, once that "duplicate" entry is removed the URL_MAPPINGS_HOLDER exception goes away.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 2.2.1, 2.2.3 and Java 1.7

jphiloon
Well, one more note, after refreshing my memory on the "/" vs. "//" variation.  It turns out some clients insert an empty context root (the app runs as ROOT on tomcat), resulting in a request of the form
http://<host>:<port>//controller/action...
vs.
http://<host>:<port>/controller/action...

The seemingly duplicate mappings are there in order to service both request forms.

Is there a way to support both request forms in UrlMappings?  Why does this only cause a problem with java 1.7?  Is this a bug or a "feature"?

Thanks,
Jay
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 2.2.1, 2.2.3 and Java 1.7

jphiloon
This post was updated on .
The error seems to be associated with RegexUrlMapping, these lines:

        final int thisStaticTokenCount = getStaticTokenCount(this);
        final int otherStaticTokenCount = getStaticTokenCount(other);
        if (otherStaticTokenCount==0 && thisStaticTokenCount>0) {
            return 1;
        }
        if (thisStaticTokenCount==0&&otherStaticTokenCount>0) {
            return -1;
        }

        final int staticDiff = thisStaticTokenCount - otherStaticTokenCount;
        if (staticDiff != 0) return staticDiff;        String[] thisTokens = getUrlData().getTokens();
        String[] otherTokens = other.getUrlData().getTokens();
        for (int i = 0; i < thisTokens.length; i++) {
            boolean thisTokenIsWildcard = isSingleWildcard(thisTokens[i]);
            boolean otherTokenIsWildcard = isSingleWildcard(otherTokens[i]);

The exception is related to otherTokens[i] being null in the last line.  The mismatch in the number of tokens should have been trapped earlier when evaluating staticTokenCount.  The tokens for the two conflicting  are these:
    [assets, service-config]
    [, assets, service-config]

The code determining staticTokenCount is this:
private int getStaticTokenCount(UrlMapping mapping) {
        String[] tokens = mapping.getUrlData().getTokens();
        int count = 0;
        for (String token : tokens) {
            if (!isSingleWildcard(token) && !"".equals(token)) count++;
        }
        return count;
    }

We see that null tokens do not contribute to the count, yet they are part of the iterated sequence. Should "thisTokens" be the longer of the two, "otherTokens" will fail with an ArrayIndexOutOfBoundsException, as we see in the stack trace.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails 2.2.1, 2.2.3 and Java 1.7

jphiloon
This issue has been entered into Grails Jira #11429.
Loading...