Github user netomi commented on the pull request:

    https://github.com/apache/commons-lang/pull/98#issuecomment-113803944
  
    This technique is used already elsewhere, e.g. in Android 
(https://android.googlesource.com/platform/libcore/+/jb-mr2-release/luni/src/main/java/libcore/util/SneakyThrow.java),
 okio 
(https://github.com/square/okio/blob/master/okio/src/main/java/okio/Util.java), 
lombok (https://projectlombok.org/features/SneakyThrows.html).
    
    There are basically two patterns that I found where this would be 
acceptable and is actually used:
    
     * in code which offers a strict interface, like Runnable.run() but we know 
for sure that any thrown exception will be caught (if executed within a Thread 
for example).
     * in cleanup code, that first collects some throwable, and at the end 
rethrows it, but the method itself does declare the checked exception, Example:
    
    ```java
    // The following code must enumerate several types to rethrow:
    public void close() throws IOException {
        Throwable thrown = null;
        ...
        if (thrown != null) {
            if (thrown instanceof IOException) {
                throw (IOException) thrown;
            } else if (thrown instanceof RuntimeException) {
                throw (RuntimeException) thrown;
            } else if (thrown instanceof Error) {
                throw (Error) thrown;
            } else {
                throw new AssertionError();
            }
        }
    }
    
    // With SneakyThrow, rethrowing is easier:
    public void close() throws IOException {
        Throwable thrown = null;
        ...
        if (thrown != null) {
            SneakyThrow.sneakyThrow(thrown);
        }
    }
    ```
    
    I am not sure if there are other use-cases that would be acceptable, but 
alone the fact that it is a dangerous technique and should only used with great 
care is a good indication to not include it in commons-lang.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to