StripeClientBuilder throws an exception with null apiKey
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Inizia in src/main/java/com/stripe/StripeClient.java, nei pressi dell'implementazione collegata di StripeClientBuilder.setApiKey, e segui il percorso di convalida di build(). Controlla in che modo un client senza una chiave globale ottiene le credenziali da RequestOptions, quindi verifica che la costruzione abbia esito positivo con una chiave null e che le chiamate che usano chiavi per richiesta si comportino come previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
When initializing StripeClient using StripeClient.builder(), providing a null value for the API key via .setApiKey(null) is allowed by the builder's interface. However, calling .build() on this builder results in an IllegalArgumentException because a global API key is expected at build time.
In a multi-tenant environment, it's common to use a single StripeClient instance and provide the specific tenant's API key with each request using RequestOptions.builder().setApiKey("sk_..."). In such scenarios, a global API key for the StripeClient itself is not necessary and might even be undesirable.
Currently, the SDK mandates a non-null API key during StripeClient construction, even if RequestOptions will be used for every subsequent API call.
To Reproduce
Attempt to build a StripeClient with a null API key:
try {
StripeClient client = StripeClient.builder()
.setApiKey(null) // Explicitly setting null, or not calling setApiKey if it defaults to null internally and is checked
.build();
// Potentially make a call, though the build() itself might fail
// CustomerCollection customers = client.customers().list(RequestOptions.builder().setApiKey("sk_test_specific_tenant").build());
} catch (Exception e) {
e.printStackTrace(); // Observe the exception during build()
}
Expected behavior
It should be possible to construct a StripeClient instance without a globally configured API key (i.e., with apiKey being null or not set on the builder) if the intention is to always provide the API key per request via RequestOptions.
The StripeClient.build() method should not throw an exception if no global API key is provided, and the responsibility for providing the API key should then fall entirely on the RequestOptions for each API call. If an API call is made without an API key in RequestOptions (and no global key is set), then an exception at that point would be appropriate.
Code snippets
OS
macOS
Java version
Java 21
stripe-java version
29.0.0
API version
2025-03-31.basil
Additional context
StripeClientBuilder.setApiKey does handle null apiKey so I don't get it why it's not accepted when the client is build.
https://github.com/stripe/stripe-java/blob/d177cbc62bb595399e298288fe9803c1d213a3ac/src/main/java/com/stripe/StripeClient.java#L519-L526
- Lingua principale
- Java
- Stelle
- 1k
- Fork
- 406
- Merge medio
- 2g 18h
- PR unite (30g)
- 20
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di stripe/stripe-java
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
stripe/stripe-java#2280 · 4 commenti ·
-
feature-request future
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
stripe/stripe-java#2024 · 5 commenti · 3 reazioni ·
-
feature-request future
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
stripe/stripe-java#1964 · 1 commento ·
-
feature-request future
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
stripe/stripe-java#1905 · 7 commenti · 7 reazioni ·
-
bug future
stripe/stripe-java#1846 · 8 commenti · 1 assegnatario ·
Tutte le issue di stripe/stripe-java
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
infinispan/infinispan#18150 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100