Uploaded image for project: 'Spring Data JPA'
  1. Spring Data JPA
  2. DATAJPA-970

Ensure JDK 6 compatibility of regular expression used in QueryUtils

    Details

      Description

      continued from https://jira.spring.io/browse/DATAJPA-965

      somehow it seems the fix of this issue (or rather one of the added regex expressions) broke java 6 compatibility (using oracle jdk1.6.0_45)?

      Caused By: java.util.regex.PatternSyntaxException: Look-behind group does not have an obvious maximum length near index 58
      \s+\w+\([0-9a-zA-z\._,\s']+\)\s+[as|AS]+\s+(?<alias>[\w\.]+)
                                                                ^
              at java.util.regex.Pattern.error(Pattern.java:1713)
              at java.util.regex.Pattern.group0(Pattern.java:2488)
              at java.util.regex.Pattern.sequence(Pattern.java:1806)
              at java.util.regex.Pattern.expr(Pattern.java:1752)
              at java.util.regex.Pattern.compile(Pattern.java:1460)
              at java.util.regex.Pattern.<init>(Pattern.java:1133)
              at java.util.regex.Pattern.compile(Pattern.java:823)
              at org.springframework.data.jpa.repository.query.QueryUtils.<clinit>(QueryUtils.java:164)
              at org.springframework.data.jpa.repository.query.JpaQueryMethod.assertParameterNamesInAnnotatedQuery(JpaQueryMethod.java:102)
              at org.springframework.data.jpa.repository.query.JpaQueryMethod.<init>(JpaQueryMethod.java:95)
              at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:77)
              at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:435)
              at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:220)
              at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:266)
              at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:252)
              at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)
      

      ref. https://github.com/spring-projects/spring-data-jpa/blame/1.10.3.RELEASE/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java#L162

        Issue Links

          Activity

          Hide
          zyro zyro added a comment -

          i am able to reproduce with this simple junit test:

          public class RegexTest {
          	@Test
          	public void test() {
          		Pattern.compile("\\s+\\w+\\([0-9a-zA-z\\._,\\s']+\\)\\s+[as|AS]+\\s+(?<alias>[\\w\\.]+)");
          	}
          }
          

          fails with jdk 6u45, works with jdk 8u45... unfortunately i have no jdk 6u65 available right now.
          but as 6u45 seems to be the latest public release (for windows at least.. sigh..), it would be great if that is still supported.

          i do not like asking for jdk6 support. not at all. but we have to deploy a few apps to a jee 6 container...

          thanks for your help! much appreciated.

          Show
          zyro zyro added a comment - i am able to reproduce with this simple junit test: public class RegexTest { @Test public void test() { Pattern.compile( "\\s+\\w+\\([0-9a-zA-z\\._,\\s']+\\)\\s+[as|AS]+\\s+(?<alias>[\\w\\.]+)" ); } } fails with jdk 6u45, works with jdk 8u45... unfortunately i have no jdk 6u65 available right now. but as 6u45 seems to be the latest public release (for windows at least.. sigh..), it would be great if that is still supported. i do not like asking for jdk6 support. not at all. but we have to deploy a few apps to a jee 6 container... thanks for your help! much appreciated.
          Hide
          cstrobl Christoph Strobl added a comment -

          thanks zyro!
          I changed the pattern a bit which now runs on 1.6.0_65-b14-462-11M4609 for mac.
          Would you mind running the following on your windows machine - just to double check.

          @Test
          public void test() {
           
          	Pattern pattern = Pattern.compile("\\s+\\w+\\([0-9a-zA-z\\._,\\s']+\\)\\s+[as|AS]+\\s+(([\\w\\.])+)");
           
          	Matcher matcher = pattern.matcher(" AVG(m.price) AS m.avg ");
          	String alias = "";
          	while (matcher.find()) {
          		alias = matcher.group(1);
          	}
           
          	assertThat(alias, is(equalTo("m.avg")));
          }
          

          Show
          cstrobl Christoph Strobl added a comment - thanks zyro ! I changed the pattern a bit which now runs on 1.6.0_65-b14-462-11M4609 for mac. Would you mind running the following on your windows machine - just to double check. @Test public void test() {   Pattern pattern = Pattern.compile( "\\s+\\w+\\([0-9a-zA-z\\._,\\s']+\\)\\s+[as|AS]+\\s+(([\\w\\.])+)" );   Matcher matcher = pattern.matcher( " AVG(m.price) AS m.avg " ); String alias = "" ; while (matcher.find()) { alias = matcher.group( 1 ); }   assertThat(alias, is(equalTo( "m.avg" ))); }
          Hide
          olivergierke Oliver Gierke added a comment -

          Applied Christoph's pull request to master and all bug fix branches that have been upgraded to fix DATAJPA-965.

          zyro — Which release train version are you using currently?

          Show
          olivergierke Oliver Gierke added a comment - Applied Christoph's pull request to master and all bug fix branches that have been upgraded to fix DATAJPA-965 . zyro — Which release train version are you using currently?
          Hide
          zyro zyro added a comment - - edited

          Christoph Strobl: test runs fine on win x64 oracle jdk6u45. thanks!
          Oliver Gierke: running 1.10.3 (Hopper SR3)

          Show
          zyro zyro added a comment - - edited Christoph Strobl : test runs fine on win x64 oracle jdk6u45. thanks! Oliver Gierke : running 1.10.3 (Hopper SR3)

            People

            • Assignee:
              olivergierke Oliver Gierke
              Reporter:
              zyro zyro
              Last updater:
              Oliver Gierke
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Agile