ClosestLocaleMatcher replaces exact locales with the last registered variant (en_US / en_PT)

Aperta Adatta ai principianti
#1,909 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #1910 di @peepsii — chiusa senza merge

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java
Ambito
backend

Direzione di ricerca

Leggi proxy/src/main/java/com/velocitypowered/proxy/util/ClosestLocaleMatcher.java e verifica come registerKnown e lookupClosest gestiscono le locale esatte e i fallback per lingua. Poi controlla la registrazione del catalogo in VelocityServer.java e la visualizzazione dei messaggi in ConnectedPlayer.java per avere il contesto. Aggiungi test per entrambi gli ordini di registrazione; il lavoro è concluso quando en_US e en_PT vengono risolte esattamente in entrambi gli ordini e il fallback continua a funzionare quando una locale esatta non è disponibile.

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

Descrizione

Expected Behavior

A registered exact locale should be retained: en_US clients should use US English and en_PT clients should use Pirate English, independently of catalogue registration order. Same-language fallback should apply when the exact locale is unavailable.

Actual Behavior

ClosestLocaleMatcher maps both locales to whichever English locale was registered last. Registering US then Pirate makes an en_US client receive Pirate translations; reversing the order makes a real en_PT client receive US English.

This can affect native messages such as velocity.kick.shutdown. The native catalogue loader uses an unsorted Files.walk, so regional-variant selection can depend on filesystem enumeration order.

Steps to Reproduce

The following standalone program uses the existing native class from the unchanged official Velocity JAR. It starts no proxy and loads no plugins.

Save as LocaleMatcherRepro.java:

import com.velocitypowered.proxy.util.ClosestLocaleMatcher;
import java.util.List;
import java.util.Locale;

public final class LocaleMatcherRepro {
  public static void main(String[] args) {
    Locale us = Locale.US;
    Locale pirate = Locale.forLanguageTag("en-PT");
    ClosestLocaleMatcher matcher = ClosestLocaleMatcher.INSTANCE;
    boolean usFirst = args[0].equals("US_FIRST");
    matcher.registerKnown(usFirst ? us : pirate);
    matcher.registerKnown(usFirst ? pirate : us);
    for (Locale requested : List.of(us, pirate)) {
      System.out.println(requested.toLanguageTag() + " -> "
          + matcher.lookupClosest(requested).toLanguageTag());
    }
  }
}

With JDK 25 and the official velocity-4.2.0-30.jar, run each case in a fresh JVM (Unix classpath syntax):

javac --release 25 -cp velocity-4.2.0-30.jar LocaleMatcherRepro.java
java -cp velocity-4.2.0-30.jar:. LocaleMatcherRepro US_FIRST
java -cp velocity-4.2.0-30.jar:. LocaleMatcherRepro PT_FIRST

Actual first invocation:

en-US -> en-PT
en-PT -> en-PT

Actual second invocation:

en-US -> en-US
en-PT -> en-US

Expected output from both invocations:

en-US -> en-US
en-PT -> en-PT
Plugin List

None in the standalone reproduction. No backend server is involved.

Velocity Version

Reproduced with official Velocity 4.2.0 build 30, upstream commit c10b49255447694ad42c3c189d7a3f4ee3e73e5e, OpenJDK 25.0.3.

Official JAR SHA-256: 35a5596a5468a035d8a32c8de5ebb0dc6b8d8f0cc3ff5169d514aca762af8aa8.

Official build metadata.

This is a standalone class reproduction, so there is no running proxy's /velocity info output for the fixture. The latest binary has not been run. The inspected current dev/4.0.0 commit, 5e8f92b98e6870c0118dadfdff42479d680654cc, still has the byte-identical matcher source linked below.

Additional Information

Relevant upstream code:

A possible minimal fix is to retain the registered exact locales and prefer an exact match before family fallback; registrations should also invalidate any affected fallback cache. This would preserve true Pirate clients and normal US clients without relying on file order.

Lingua principale
Java
Stelle
2.3k
Fork
983
Merge medio
4g 14h
PR unite (30g)
3

Preparare l'ambiente

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 PaperMC/Velocity

Tutte le issue di PaperMC/Velocity

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.