IndexOutOfBoundsException - Wrong formatted content when dealing with latex String
Maintainer antworten meist innerhalb von 1 Tag
@Amlan2000 arbeitet bereits daran.
Seit 15.8.2026.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 55/100
Rechercherichtung
Reproduziere den Fehler mit der bereitgestellten Java-Klasse und untersuche anschließend StringWrapper#applyReplacements und FormatterException#formatDiagnostics. Vergleiche den generierten Quelltext und die Verarbeitung der Diagnosezeile mit der ursprünglichen Eingabe. Erledigt ist die Aufgabe, wenn die Formatierung keinen nicht kompilierbaren Java-Code mehr erzeugt und der Formatter den Fehler ohne IndexOutOfBoundsException meldet.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Give this class
package question;
class T {
private static final String JSON =
"{\n"
+ " \"a\": \"AAAAA AAA AAA AAA AA AAA AA AAAAA AA AAAAA AAA AAAA AAAA AA AAAA AAAA AAAAA AAAAA AAAAA AAAAA AAAAAA AAAAA AAAAAA AAAAA AAA at $-15.4{^{\\\\,\\\\circ}\\\\text{C}}$ BBB BBBBB BB BBB $42.7{^{\\\\,\\\\circ}\\\\text{C}}$?\\n\\n(CC CC CCC CC CCCCC CCC CCC CCC CCC CCC CC = $1.95\\\\;{\\\\text{J}/\\\\text{g}\\\\cdot{^{\\\\circ}\\\\text{C}}}$; DDD DDD DDDD DDDD DDDDD DDDD DDD DD DDDD = $1.18\\\\;{\\\\text{J}/\\\\text{g}\\\\cdot{^{\\\\circ}\\\\text{C}}}$C; $\\\\Delta H_\\\\text{fus}$ = 5.72 kJ/mol; normal freezing point, $T_f$ = $28.3{^{\\\\,\\\\circ}\\\\text{C}}$)\",\n"
+ " \"b\": \"*EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EEE.*\\n\\nFF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F $-15.4^\\\\circ\\\\text C$ to $28.3^\\\\circ\\\\text C$.\\n\\\\[q=mc\\\\Delta T=(10.1\\\\;\\\\mathrm{g})(1.95\\\\;\\\\mathrm{J/g\\\\cdot °C})(28.3\\\\;\\\\mathrm{ °C}-(-15.4)\\\\;\\\\mathrm{ °C})=860.6715\\\\;\\\\mathrm{J} \\\\]\\n\\nGG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GGGGGGGGGGGGGGGGGGGGG.\\n\\\\[q=nH_{fus}=(\\\\frac{10.1\\\\;\\\\mathrm{g}}{67.44\\\\;\\\\mathrm{g/mol}})(5720\\\\;\\\\mathrm{J})=856.6429\\\\;\\\\mathrm{J}\\\\]\\n\\nHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH $28.3^\\\\circ\\\\text C$ to $42.7^\\\\circ\\\\text C$.\\n\\\\[q=mc\\\\Delta T=(10.1\\\\;\\\\mathrm{g})(1.18\\\\;\\\\mathrm{J/g\\\\cdot °C})(42.7\\\\;\\\\mathrm{ °C}-28.3\\\\;\\\\mathrm{ °C})=171.6192\\\\;\\\\mathrm{J}\\\\]\\n\\nIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII.\\n\\\\[860.6715\\\\;\\\\mathrm{J}+856.6429\\\\;\\\\mathrm{J}+171.6192\\\\;\\\\mathrm{J}=1888.9336\\\\;\\\\mathrm{J}=1.89\\\\;\\\\mathrm{kJ}\\\\]\",\n"
+ "}";
private static final String JSON2 =
"{\n"
+ " \"a\": \"AAAAA AAA AAA AAA AA AAA AA AAAAA AA AAAAA AAA AAAA AAAA AA AAAA AAAA AAAAA AAAAA AAAAA AAAAA AAAAAA AAAAA AAAAAA AAAAA AAA at $-15.4{^{\\\\,\\\\circ}\\\\text{C}}$ BBB BBBBB BB BBB $42.7{^{\\\\,\\\\circ}\\\\text{C}}$?\\n\\n(CC CC CCC CC CCCCC CCC CCC CCC CCC CCC CC = $1.95\\\\;{\\\\text{J}/\\\\text{g}\\\\cdot{^{\\\\circ}\\\\text{C}}}$; DDD DDD DDDD DDDD DDDDD DDDD DDD DD DDDD = $1.18\\\\;{\\\\text{J}/\\\\text{g}\\\\cdot{^{\\\\circ}\\\\text{C}}}$C; $\\\\Delta H_\\\\text{fus}$ = 5.72 kJ/mol; normal freezing point, $T_f$ = $28.3{^{\\\\,\\\\circ}\\\\text{C}}$)\",\n"
+ " \"b\": \"*EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EEE.*\\n\\nFF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F $-15.4^\\\\circ\\\\text C$ to $28.3^\\\\circ\\\\text C$.\\n\\\\[q=mc\\\\Delta T=(10.1\\\\;\\\\mathrm{g})(1.95\\\\;\\\\mathrm{J/g\\\\cdot °C})(28.3\\\\;\\\\mathrm{ °C}-(-15.4)\\\\;\\\\mathrm{ °C})=860.6715\\\\;\\\\mathrm{J} \\\\]\\n\\nGG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GGGGGGGGGGGGGGGGGGGGG.\\n\\\\[q=nH_{fus}=(\\\\frac{10.1\\\\;\\\\mathrm{g}}{67.44\\\\;\\\\mathrm{g/mol}})(5720\\\\;\\\\mathrm{J})=856.6429\\\\;\\\\mathrm{J}\\\\]\\n\\nHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH $28.3^\\\\circ\\\\text C$ to $42.7^\\\\circ\\\\text C$.\\n\\\\[q=mc\\\\Delta T=(10.1\\\\;\\\\mathrm{g})(1.18\\\\;\\\\mathrm{J/g\\\\cdot °C})(42.7\\\\;\\\\mathrm{ °C}-28.3\\\\;\\\\mathrm{ °C})=171.6192\\\\;\\\\mathrm{J}\\\\]\\n\\nIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII.\\n\\\\[860.6715\\\\;\\\\mathrm{J}+856.6429\\\\;\\\\mathrm{J}+171.6192\\\\;\\\\mathrm{J}=1888.9336\\\\;\\\\mathrm{J}=1.89\\\\;\\\\mathrm{kJ}\\\\]\",\n"
+ "}";
public static void main(String[] args) {
System.out.println(JSON);
}
}
I ran the main method to ensure it is valid java source code
But when trying to format it using GJF, I got
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 42 out of bounds for length 22
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:100)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
at java.base/java.util.Objects.checkIndex(Objects.java:385)
at java.base/java.util.ArrayList.get(ArrayList.java:427)
at java.base/java.util.Collections$UnmodifiableList.get(Collections.java:1502)
at com.google.googlejavaformat.java.FormatterException.formatDiagnostics(FormatterException.java:70)
at com.google.googlejavaformat.java.Main.formatFiles(Main.java:177)
at com.google.googlejavaformat.java.Main.format(Main.java:128)
at com.google.googlejavaformat.java.Main.main(Main.java:91)
at com.google.googlejavaformat.java.Main.main(Main.java:81)
at com.google.googlejavaformat.java.Main.main(Main.java:70)
Digging into the GJF, I found 2 issues:
- The
com.google.googlejavaformat.java.StringWrapper#applyReplacementsgive wrong result:
package question;
class T {
private static final String JSON =
"{\n"
+ " \"a\": \"AAAAA AAA AAA AAA AA AAA AA AAAAA AA AAAAA AAA AAAA AAAA AA AAAA AAAA AAAAA"
+ " AAAAA AAAAA AAAAA AAAAAA AAAAA AAAAAA AAAAA AAA at $-15.4{^{\\\\,\\\\circ}\\\"
+ "\text{C}}$ BBB BBBBB BB BBB $42.7{^{\\\\,\\\\circ}\\\\text{C}}$?\\n"
+ "\\n"
+ "(CC CC CCC CC CCCCC CCC CCC CCC CCC CCC CC = $1.95\\\\;{\\\\text{J}/\\\"
+ "\text{g}\\\\cdot{^{\\\\circ}\\\\text{C}}}$; DDD DDD DDDD DDDD DDDDD DDDD DDD DD DDDD ="
+ " $1.18\\\\;{\\\\text{J}/\\\\text{g}\\\\cdot{^{\\\\circ}\\\\text{C}}}$C; $\\\\Delta"
+ " H_\\\\text{fus}$ = 5.72 kJ/mol; normal freezing point, $T_f$ ="
+ " $28.3{^{\\\\,\\\\circ}\\\\text{C}}$)\",\n"
+ " \"b\": \"*EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE"
+ " EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE"
+ " EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EEE.*\\n"
+ "\\n"
+ "FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F"
+ " $-15.4^\\\\circ\\\\text C$ to $28.3^\\\\circ\\\\text C$.\\n"
+ "\\\\[q=mc\\\\Delta T=(10.1\\\\;\\\\mathrm{g})(1.95\\\\;\\\\mathrm{J/g\\\\cdot"
+ " °C})(28.3\\\\;\\\\mathrm{ °C}-(-15.4)\\\\;\\\\mathrm{ °C})=860.6715\\\\;\\\\mathrm{J}"
+ " \\\\]\\n"
+ "\\n"
+ "GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG"
+ " GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GGGGGGGGGGGGGGGGGGGGG.\\n"
+ "\\\\[q=nH_{fus}=(\\\\frac{10.1\\\\;\\\\mathrm{g}}{67.44\\\\;\\\\mathrm{g/mol}})(5720\\\\;\\\\mathrm{J})=856.6429\\\\;\\\\mathrm{J}\\\\]\\n"
+ "\\n"
+ "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH $28.3^\\\\circ\\\\text C$ to"
+ " $42.7^\\\\circ\\\\text C$.\\n"
+ "\\\\[q=mc\\\\Delta T=(10.1\\\\;\\\\mathrm{g})(1.18\\\\;\\\\mathrm{J/g\\\\cdot"
+ " °C})(42.7\\\\;\\\\mathrm{ °C}-28.3\\\\;\\\\mathrm{"
+ " °C})=171.6192\\\\;\\\\mathrm{J}\\\\]\\n"
+ "\\n"
+ "IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII.\\n"
+ "\\\\[860.6715\\\\;\\\\mathrm{J}+856.6429\\\\;\\\\mathrm{J}+171.6192\\\\;\\\\mathrm{J}=1888.9336\\\\;\\\\mathrm{J}=1.89\\\\;\\\\mathrm{kJ}\\\\]\",\n"
+ "}";
private static final String JSON2 =
"{\n"
+ " \"a\": \"AAAAA AAA AAA AAA AA AAA AA AAAAA AA AAAAA AAA AAAA AAAA AA AAAA AAAA AAAAA"
+ " AAAAA AAAAA AAAAA AAAAAA AAAAA AAAAAA AAAAA AAA at $-15.4{^{\\\\,\\\\circ}\\\"
+ "\text{C}}$ BBB BBBBB BB BBB $42.7{^{\\\\,\\\\circ}\\\\text{C}}$?\\n"
+ "\\n"
+ "(CC CC CCC CC CCCCC CCC CCC CCC CCC CCC CC = $1.95\\\\;{\\\\text{J}/\\\"
+ "\text{g}\\\\cdot{^{\\\\circ}\\\\text{C}}}$; DDD DDD DDDD DDDD DDDDD DDDD DDD DD DDDD ="
+ " $1.18\\\\;{\\\\text{J}/\\\\text{g}\\\\cdot{^{\\\\circ}\\\\text{C}}}$C; $\\\\Delta"
+ " H_\\\\text{fus}$ = 5.72 kJ/mol; normal freezing point, $T_f$ ="
+ " $28.3{^{\\\\,\\\\circ}\\\\text{C}}$)\",\n"
+ " \"b\": \"*EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE"
+ " EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE"
+ " EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EEE.*\\n"
+ "\\n"
+ "FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F"
+ " $-15.4^\\\\circ\\\\text C$ to $28.3^\\\\circ\\\\text C$.\\n"
+ "\\\\[q=mc\\\\Delta T=(10.1\\\\;\\\\mathrm{g})(1.95\\\\;\\\\mathrm{J/g\\\\cdot"
+ " °C})(28.3\\\\;\\\\mathrm{ °C}-(-15.4)\\\\;\\\\mathrm{ °C})=860.6715\\\\;\\\\mathrm{J}"
+ " \\\\]\\n"
+ "\\n"
+ "GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG"
+ " GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GG GGGGGGGGGGGGGGGGGGGGG.\\n"
+ "\\\\[q=nH_{fus}=(\\\\frac{10.1\\\\;\\\\mathrm{g}}{67.44\\\\;\\\\mathrm{g/mol}})(5720\\\\;\\\\mathrm{J})=856.6429\\\\;\\\\mathrm{J}\\\\]\\n"
+ "\\n"
+ "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH $28.3^\\\\circ\\\\text C$ to"
+ " $42.7^\\\\circ\\\\text C$.\\n"
+ "\\\\[q=mc\\\\Delta T=(10.1\\\\;\\\\mathrm{g})(1.18\\\\;\\\\mathrm{J/g\\\\cdot"
+ " °C})(42.7\\\\;\\\\mathrm{ °C}-28.3\\\\;\\\\mathrm{"
+ " °C})=171.6192\\\\;\\\\mathrm{J}\\\\]\\n"
+ "\\n"
+ "IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII.\\n"
+ "\\\\[860.6715\\\\;\\\\mathrm{J}+856.6429\\\\;\\\\mathrm{J}+171.6192\\\\;\\\\mathrm{J}=1888.9336\\\\;\\\\mathrm{J}=1.89\\\\;\\\\mathrm{kJ}\\\\]\",\n"
+ "}";
public static void main(String[] args) {
System.out.println(JSON);
}
}
This result is completely not compilable
com.google.googlejavaformat.java.FormatterException#formatDiagnosticsusing wrong param to format the diagnostics: It uses the original java content (22 lines intotal) instead of formatted java content (79 lines in total). That is why we getting IndexOutOfBoundsException
- Vorherrschende Sprache
- Java
- Sterne
- 6.2k
- Forks
- 940
- Ø Merge
- 5 Min.
- Gemergte PRs (30 T.)
- 7
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus google/google-java-format
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
google/google-java-format#1094 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
google/google-java-format#1478 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
google/google-java-format#1470 · 5 Reaktionen ·
Maintainer antworten meist innerhalb von 1 Tag
-
unused import removal leaves extra blank line between package declaration and class Javadoc / declarationEvtl. vergeben @arimu1 hat das vor 68 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 62/100
google/google-java-format#1436 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Eclipse
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 48/100
google/google-java-format#1428 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in google/google-java-format
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
apache/rocketmq-dashboard#6610 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
`RedisList.reversed()` view returns an empty `range` and `trim` removes all elementsEvtl. vergeben @CCCLL hat das heute übernommen. Offenstatus: waiting-for-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
spring-projects/spring-data-redis#3461 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 73/100
javapathfinder/jpf-core#649 ·
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
devops-thiago/ThrillhouseBot#1093 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
wimdeblauwe/htmx-spring-boot#205 ·