Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Unclosed string literal error on regex string

Open
#1,253 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
tooling

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google/google-java-format

All issues in google/google-java-format

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.