Share rationale behind explicit `throws RuntimeException` clause
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 32/100
- Tipo di issue
- Documentazione
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- java
- Ambito
- api, documentation
Direzione di ricerca
Inizia con CloudEventContextWriter.withContextAttribute(...), CloudEventContextReaderAdapter.readAttributes(), readExtensions() e readContext(), come identificato nell’issue, quindi esamina le loro dichiarazioni e i relativi Javadocs attuali. Il lavoro è completato quando sono documentati il motivo dell’API per RuntimeException e le aspettative dei chiamanti, oppure quando le dichiarazioni vengono riviste con una documentazione @throws appropriata, previo accordo dei maintainer.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Context
I'm a Java™ programmer seeking guidance on best practice and recommended Java™ programming idioms. Ordinarily, my first inclination is to defer to the most authoritative references for the Java™ programming language.
However, library authors can sometimes offer compelling rationale to do otherwise.
Java™ SE 8 Javadoc for RuntimeException:
public class RuntimeException
extendsException…
RuntimeExceptionand its subclasses are unchecked exceptions.
Unchecked exceptions do NOT need to be declared in a method
or constructor's throws clause if they can be thrown by the
execution of the method or constructor and propagate outside
the method or constructor boundary
…
Java™ Language Specification (JLS)
…
Run-time exception classes are exempted because, in the judgment of
the designers of the Java programming language, having to declare
such exceptions would not aid significantly in establishing the
correctness of programs. Many of the operations and constructs of
the Java programming language can result in exceptions at run time.
The information available to a Java compiler, and the level of analysis
a compiler performs, are usually not sufficient to establish that such
run-time exceptions cannot occur, even though this may be obvious to the
programmer. Requiring such exception classes to be declared would
simply be an irritation to programmers
…
The Issue
TL;DR — It's puzzling why some Java™ SDK for CloudEvents methods are declared with a throws RuntimeException clause.
To elaborate
I have tried to reason about what this library's API designers might have intended to communicate to callers by exposing the atypical public signatures in question. Several hypothetical questions arose. Here are three examples…
- What does this project's authors intend callers to do when calling methods declared with
throws RuntimeException? - What do you foresee would happen if callers ignore (don't handle) your methods'
throws RuntimeExceptions? - What, originally, did you foresee would happen for callers if those
throws RuntimeExceptionwere never declared? - …
Which methods?
All overloaded CloudEventContextWriter.withContextAttribute(...) methods have throws CloudEventRWException declarations…
…
CloudEventContextWriter withContextAttribute(String name, String value) throws CloudEventRWException;
…
Interestingly, the two methods CloudEventContextReaderAdapter.readAttributes() CloudEventContextReaderAdapter.readExtensions() are both declared with throws RuntimeException; the superclass of CloudEventRWException…
…
public void readAttributes(CloudEventContextWriter writer) throws RuntimeException
…
public void readExtensions(CloudEventContextWriter writer) throws RuntimeException
…
// This should never happen because we build that map only through our builders
throw new IllegalStateException("Illegal value inside extensions map: " + key + " " + value);
…
CloudEventContextReaderAdapter.readContext(CloudEventContextWriter) calls both of its sibling methods. However, it IS declared with throws CloudEventRWException…
public void readContext(CloudEventContextWriter writer) throws CloudEventRWException
Or is it just me?
The system I'm currently analyzing and will eventually implement, potentially may consume the public API of the Java™ SDK for CloudEvents.
For not only my project specifically, I imagine it would be helpful for all consuming projects in general to understand the rationale behind this SDK's atypical idiom of explicitly declaring public methods with throws RuntimeException.
Proposed Solution
There's more than one alternative that I presume would have value to the entire community. Here are just two examples…
- Add clear explanations in the Java™ SDK for CloudEvents Javadoc
- Nothing complicated; simply something that clarifies the methods in question's rationale for taking the road less traveled
- Currently, there is nothing documenting why
throws RuntimeExceptionis necessary
- Remove the explictly-declared
throws RuntimeExceptionclauses- But add Javadoc that uses the
@throwsannotation appropriately to document what callers of the method should expect
- But add Javadoc that uses the
- ???
- Lingua principale
- Java
- Stelle
- 446
- Fork
- 172
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
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 cloudevents/sdk-java
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
cloudevents/sdk-java#731 · 1 reazione ·
-
bug
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
cloudevents/sdk-java#697 · 3 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
cloudevents/sdk-java#689 · 2 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
cloudevents/sdk-java#660 · 2 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
cloudevents/sdk-java#711 · 1 commento ·
Tutte le issue di cloudevents/sdk-java
Issue simili
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
apache/cloudstack#14222 ·
-
[BUG]茶杯方块在取茶时会引发崩溃 Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Cannot differ own consent and managed consents in My Consents view and detailed consent view. Aperta1.0.0-alpha2 Type/Improvement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
wso2/dpdp-accelerator#272 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
infinispan/infinispan#18150 ·
-
area/frontend
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100