Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 3.1.5 doesn't work in Android #580

Closed
merlin-zaraza opened this issue Mar 1, 2021 · 9 comments · Fixed by #581 or #585
Closed

Release 3.1.5 doesn't work in Android #580

merlin-zaraza opened this issue Mar 1, 2021 · 9 comments · Fixed by #581 or #585
Milestone

Comments

@merlin-zaraza
Copy link

Seems like there are some regex patterns were added to release 3.1.5 which doesn't work in Android. Previous version (3.1.4) works well.
Here is stack trace:

Caused by java.util.regex.PatternSyntaxException: U_ILLEGAL_ARGUMENT_ERROR
^[\p{IsLetter}_][\p{IsLetter}\p{IsDigit}_]*
       at java.util.regex.Pattern.compileImpl(Pattern.java)
       at java.util.regex.Pattern.compile(Pattern.java:1344)
       at java.util.regex.Pattern.<init>(Pattern.java:1328)
       at java.util.regex.Pattern.compile(Pattern.java:950)
       at com.mitchellbosecke.pebble.lexer.LexerImpl.<clinit>(LexerImpl.java:2)
       at com.mitchellbosecke.pebble.PebbleEngine.getPebbleTemplate(PebbleEngine.java:11)
       at com.mitchellbosecke.pebble.PebbleEngine.lambda$getTemplate$2(PebbleEngine.java)
       at com.mitchellbosecke.pebble.PebbleEngine.lambda$getTemplate$2$PebbleEngine(PebbleEngine.java)
       at com.mitchellbosecke.pebble.-$$Lambda$PebbleEngine$RWC2jsSmCWn6HfuOZr1k4eoPeUE.apply(-.java:8)
       at j$.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:47)
       at j$.util.concurrent.ConcurrentMap$-EL.computeIfAbsent(ConcurrentMap.java:6)
       at com.mitchellbosecke.pebble.cache.template.ConcurrentMapTemplateCache.computeIfAbsent(ConcurrentMapTemplateCache.java:2)
       at com.mitchellbosecke.pebble.cache.template.ConcurrentMapTemplateCache.computeIfAbsent(ConcurrentMapTemplateCache.java)
       at com.mitchellbosecke.pebble.PebbleEngine.getTemplate(PebbleEngine.java:17)
       at com.mitchellbosecke.pebble.PebbleEngine.getTemplate(PebbleEngine.java:2)

According to this post https://stackoverflow.com/questions/47922686/patternsyntaxexception-when-trying-to-validate-latin-characters Android doesn't recognize Is aliases.

@ebussieres ebussieres added this to the 3.1.6 milestone Mar 1, 2021
@ebussieres
Copy link
Member

ebussieres commented Mar 2, 2021

The regex in problem is ^[\p{IsLetter}_][\p{IsLetter}\p{IsDigit}_]* and was introduced in #544

According to this spec (https://developer.android.com/reference/java/util/regex/Pattern), IsDigitcan be replaced with Digit.
Unfortunately, there's nothing for IsLetter. I tried to replace it with Alpha but some unit tests are failing

Edit Found IsAlphabetic that seems to work and exists (https://developer.android.com/reference/java/util/regex/Pattern.html#ubpc)

@ebussieres ebussieres linked a pull request Mar 2, 2021 that will close this issue
@ebussieres ebussieres reopened this Mar 2, 2021
@ebussieres
Copy link
Member

ebussieres commented Mar 2, 2021

@merlin-zaraza : Can you try the SNAPSHOT and tell me if it fixes your error ? I've no setup to test it with Android.

Here's how you can retrieve the version 3.1.6-SNAPSHOT in sonatype:
https://pebbletemplates.io/wiki/guide/installation/

@merlin-zaraza
Copy link
Author

Still not working in Android:

Caused by: java.util.regex.PatternSyntaxException: U_ILLEGAL_ARGUMENT_ERROR
	^[\p{IsAlphabetic}_][\p{IsAlphabetic}\p{Digit}_]*
	at java.util.regex.Pattern.compileImpl(Native Method)
	at java.util.regex.Pattern.compile(Pattern.java:1340)
	at java.util.regex.Pattern.<init>(Pattern.java:1324)
	at java.util.regex.Pattern.compile(Pattern.java:946)
	at com.mitchellbosecke.pebble.lexer.LexerImpl.<clinit>(LexerImpl.java:93)

@merlin-zaraza
Copy link
Author

Seems like it's Android part so I've submitted bug to Android issue tracker https://issuetracker.google.com/issues/181655428.
Would be appreciate for workaround, maybe you can create regex pattern without aliases.

@ogrammer
Copy link
Contributor

ogrammer commented Mar 13, 2021

Unfortunately Android is not using real Java so they are not using the standard RegEx engine either but ICU instead. ICU has different naming for some things. When I created the pull request, I did take Android into account so I'm not sure why it does not work for you. If I remember correctly, I even tested the pattern.

@ogrammer
Copy link
Contributor

ogrammer commented Mar 13, 2021

I just tested on Android 10 and it works fine, but on Android up to (and perhaps past) 7 it crashes. The page ebusseries sent does say that Is prefix is supported for Letter and Digit but that could be a recent addition.

@ogrammer
Copy link
Contributor

It appears to have been solved in newer Android versions but to support older ones I added a static initializer check.

@ebussieres
Copy link
Member

@merlin-zaraza Can you try the SNAPSHOT and tell me if it fixes your error ?

@merlin-zaraza
Copy link
Author

@merlin-zaraza Can you try the SNAPSHOT and tell me if it fixes your error ?

Works now. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants