question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

throws clauses are simplified

See original GitHub issue

CFR version

0.149-SNAPSHOT (commit 254c677)

Compiler

javac 11.0.5

Description

throws clauses are simplified, duplicate declared exceptions are omitted and generic types are reduced to their erasure type. While this results in functionally equivalent code, the difference can be detected using reflection.

Source:

class ThrowsClauseExact<E extends Exception> {
    public void testThrow() throws Exception, E, E, RuntimeException, RuntimeException { }
    
    public static void main(String... args) throws Exception {
        System.out.println(ThrowsClauseExact.class.getMethod("testThrow").getExceptionTypes().length);
    }
}

Decompiled output:

class ThrowsClauseExact<E extends Exception> {
    ThrowsClauseExact() {
    }

    public void testThrow() throws RuntimeException, Exception {
    }

    public static void main(String ... arrstring) throws Exception {
        System.out.println(ThrowsClauseExact.class.getMethod("testThrow", new Class[0]).getExceptionTypes().length);
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
leibnitz27commented, Feb 27, 2020

Lol. I had to.

ThrowsClauseExact2.class.txt

@ItzSomebody - Chris, you might find that one amusing in fernflower.

0reactions
leibnitz27commented, Mar 2, 2020

Did you try decompiling the above in idea/fernflower? 😃 Not so much a side effect in the class file, rather one left for the unwary reader, or the immediate recompiler - It’s a bit silly, but it’s a fun trap to leave…

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.benf.cfr.tests;

class ThrowsClauseExact2<EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE extends Exception> {
    ThrowsClauseExact2() {
    }

    public void testThrow() throws Exception { System.out.println("They found me.  I don't know how, but they found me..");} {
    }

    public static void main(String... args) throws Exception {
        (new ThrowsClauseExact2()).testThrow();
    }
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Throws Keyword in Java | Throws Clause - Scientech Easy
Throws clause consists of throws keyword followed by a comma-separated by the list of all exceptions thrown by that method. Throws Keyword in...
Read more >
What is the point in throws clause? - Stack Overflow
The throws clause says that a method is allowed to throw certain exceptions. It sets out the contract that the method has with...
Read more >
throw and throws in Java - GeeksforGeeks
The throw keyword in Java is used to explicitly throw an exception from a method or any block of code. We can throw...
Read more >
Throw and Throws in Java - C# Corner
This article has explained the throw statement and the throws clause in Java. These keywords are very important in exception handling in ...
Read more >
Java Throws Keyword in Exception handling - BeginnersBook
The throws keyword is used to handle checked exceptions. As we learned in the previous article that exceptions are of two types: checked...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found