Unclosed string literal error on regex string
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
Research direction
Start with the simplified Java reproducer in the issue and run google-java-format 1.26.0 through the documented java -jar command. Trace how the formatter parses string literals containing regex backslashes and determine why the valid source is reported as an unclosed string literal. Done means the reproducer formats without that error.
Written by the indexing model from the issue text.
Description
Hello, I found this issue when updating the formatter version in googleapis/java-spanner
package com.example;
final class Test {
// Error: unclosed string literal
String breaks = "'\\d{2}):(\\d{2}):(\\d{2})(\\.\\d{1,9})?)([Zz]|([+-])(\\d{2}):(\\d{2})))|(READ_TIMESTAMP)[\\t";
// Works
String fix = "'\\d{2}):(\\d{2}):(\\d{2})(\\.\\d{1,9})?)([Zz]|([+-])(\\d{2}):(\\d{2})))|(READ_TIMESTAMP)[\u005Ct";
}
Produces the following error:
hi on] diegomarquezp:java-spanner$ java -jar ~/.library_generation/google-java-format.jar --version
google-java-format: Version 1.26.0
[hi on] diegomarquezp:java-spanner$ java -jar ~/.library_generation/google-java-format.jar test.java
test.java:7:13: error: unclosed string literal
String fix = "'((STRONG)|(MIN_READ_TIMESTAMP)[\\t ]+((\\d{4})-(\\d{2})-(\\d{2})([Tt](\\d{2}):(\\d{2}):(\\d{2})(\\.\\d{1,9})?)([Zz]|([+-])(\\d{2}):(\\d{2})))|(READ_TIMESTAMP)[\u005Ct ]+((\\d{4})-(\\d{2})-(\\d{2})([Tt](\\d{2}):(\\d{2}):( \\d{2})(\\.\\d{1,9})?)([Zz]|([+-])(\\d{2}):(\\d{2})))|(MAX_STALENESS)[\u005Ct ]+((\\d{1,19})(s|ms|us|ns))|(EXACT_STALENESS)[\\t ]+((\\d{1,19})(s|ms|us|ns)))'";
^
[hi on] diegomarquezp:java-spanner$
Note that String fix doesn't have the error after replacing these two specific double backslashes \\ with the hexcode version \u0005C.
update: simplified reproducer code.
- Dominant language
- Java
- Stars
- 6.2k
- Forks
- 936
- Avg merge
- 6m
- Merged PRs (30d)
- 2
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from google/google-java-format
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
google/google-java-format#1094 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
google/google-java-format#1439 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 62/100
google/google-java-format#1436 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
google/google-java-format#1428 · 4 comments ·
-
Eclipse
Difficulty 3/5 1-2 days Newbie friendliness 55/100
google/google-java-format#1417 ·
All issues in google/google-java-format
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
feature triaged
Difficulty 1/5 Under an hour Newbie friendliness 75/100
Graylog2/graylog2-server#27549 ·
Maintainers usually reply within 1 day
-
component/zeebe kind/bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
UniversalMediaServer/UniversalMediaServer#6356 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
googleapis/google-cloud-java#14533 ·
Maintainers usually reply within 1 day