Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Unexpected handling of lines with less than 100 characters

Aperta
#567 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
java
Ambito
tooling

Direzione di ricerca

Riproduci il problema con test.java utilizzando l’invocazione da riga di comando di google-java-format-1.9-all-deps.jar mostrata nel report, confrontando l’output precedente, successivo e previsto. Traccia il comportamento del formatter per le stringhe SQL multilinea; il lavoro è completato quando viene suddivisa solo la riga troppo lunga, mentre le altre righe più corte mantengono la formattazione originale.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

I have some quite large sql multiline string and when one line is over 100 characters it will re-format it onto 2 lines. While I believe this is the correct behaviour to split this long line, it also re-formats all of the other lines of the String which I don't think should happen as they are under 100 characters long, therefore I think this is a bug.

NB: Because of https://github.com/google/google-java-format/issues/566 you can only see this happening using the jar on the command line as per the example below:

before - unformatted file:

package x;

public class test {

  static final String MY_SQL_QUERY =
      "SELECT "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, "
          + "  l.some_really_long_column_name    AS some_really_looooooooooooooooooooong_column_name, "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, ";

  public test() {
    int x=1;if(x==1){x=2;}else{x=3;}
  }

}

apply google java formatting:

/tmp $ java -version
openjdk version "11.0.9" 2020-10-20
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9+11)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.9+11, mixed mode)
/tmp $ cksum ~/lib/google-java-format-1.9-all-deps.jar
2002751029 3404610 ~/lib/google-java-format-1.9-all-deps.jar
/tmp $ java -jar ~/lib/google-java-format-1.9-all-deps.jar ./test.java

after - formatted by google java formatter:

package x;

public class test {

  static final String MY_SQL_QUERY =
      "SELECT   customer_id             AS customer_id,   customer_id             AS customer_id, "
          + "  customer_id             AS customer_id,   customer_id             AS customer_id,  "
          + " customer_id             AS customer_id,   l.some_really_long_column_name    AS"
          + " some_really_looooooooooooooooooooong_column_name,   customer_id             AS"
          + " customer_id,   customer_id             AS customer_id, ";

  public test() {
    int x = 1;
    if (x == 1) {
      x = 2;
    } else {
      x = 3;
    }
  }
}

Expected - this is what I think google java formatter should do:

package x;

public class test {

  static final String MY_SQL_QUERY =
      "SELECT "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, "
          + "  l.some_really_long_column_name    "
                 + "AS some_really_looooooooooooooooooooong_column_name, "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, ";

  public test() {
    int x = 1;
    if (x == 1) {
      x = 2;
    } else {
      x = 3;
    }
  }
}
Lingua principale
Java
Stelle
6.2k
Fork
936
Merge medio
6m
PR unite (30g)
3

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di google/google-java-format

Tutte le issue di google/google-java-format

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.