[jira] [Updated] (LUCENE-7800) Remove code that potentially rethrows checked exceptions from methods that don't declare them ("sneaky throw" hack)
[ https://issues.apache.org/jira/browse/LUCENE-7800?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Dawid Weiss updated LUCENE-7800: Attachment: LUCENE-7800.patch Precommit (javadoc) and ParseException unwrapping in the compiler pulled up. > Remove code that potentially rethrows checked exceptions from methods that > don't declare them ("sneaky throw" hack) > --- > > Key: LUCENE-7800 > URL: https://issues.apache.org/jira/browse/LUCENE-7800 > Project: Lucene - Core > Issue Type: Task >Reporter: Dawid Weiss >Assignee: Dawid Weiss >Priority: Minor > Fix For: 6.x, master (7.0) > > Attachments: LUCENE-7800.patch, LUCENE-7800.patch, LUCENE-7800.patch > > > For a long time I considered the "sneaky" throw hack to be a nice way of > coding around some of Java's limitations (especially with invoking methods > via reflection or method handles), but with time I started to see how it can > be potentially dangerous and is nearly always confusing. If you have a Java > method and its signature doesn't indicate the possibility of a checked > exception you, as a programmer, simply don't expect it to happen. Never. So, > for example, you could write: > {code} > try { > luceneApi(); > } catch (RuntimeException | Error e) { > // Handle unchecked exceptions here. > } > {code} > and consider the code above to be absolutely bullet-proof in terms of > handling exceptions. Unfortunately with sneaky throws anywhere in the > "luceneApi" this is no longer the case -- you can receive a checked exception > that will simply fall through and hit some code frame above. > So I suggest we remove sneaky throw from the core entirely. It only exists in > two places -- private methods inside Snowball programs invoked via method > handles (these don't even declare checked exceptions so I assume they can't > occur) and AttributeFactory -- here there is a real possibility somebody > could declare an attribute class's constructor that does throw an unchecked > exception. In that case I think it is more reasonable to wrap it in a > RuntimeException than rethrow it as original. > Alternatively, we can modify the signature of {{createAttributeInstance}} and > {{getStaticImplementation}} to declare some kind of checked exception (either > a wrapper or even a Throwable), but I see little reason for it and it'd > change the API. -- This message was sent by Atlassian JIRA (v6.3.15#6346) - To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org
[jira] [Updated] (LUCENE-7800) Remove code that potentially rethrows checked exceptions from methods that don't declare them ("sneaky throw" hack)
[ https://issues.apache.org/jira/browse/LUCENE-7800?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Dawid Weiss updated LUCENE-7800: Attachment: LUCENE-7800.patch I return to this issue to either resolve it or have it vetoed, because otherwise it'll be forgotted forever. Attached is a patch which removes unchecked-exception throwing hacks from the codebase for reasons I already mentioned. The changes are: 1) SnowballProgram throws an AssertionError should an exception happen in {{find_among}} (it shouldn't). 2) {{AttributeFactory}} rethrows Error and RuntimeException classes, but wraps checked exceptions in a {{AttributeInstantiationException}} that is a subclass of {{RuntimeException}}. I made the {{AttributeInstantiationException}} class public just in case somebody desperately wanted to instanceof it and get the cause. 3) JavascriptCompiler throws throws a {{RuntimeException}} with a cause set to {{ParseException}}. The code unwraps such checked parse exceptions in {{getAntlrParseTree}} anyway, so this is only an internal change. > Remove code that potentially rethrows checked exceptions from methods that > don't declare them ("sneaky throw" hack) > --- > > Key: LUCENE-7800 > URL: https://issues.apache.org/jira/browse/LUCENE-7800 > Project: Lucene - Core > Issue Type: Task >Reporter: Dawid Weiss >Assignee: Dawid Weiss >Priority: Minor > Fix For: 6.x, master (7.0) > > Attachments: LUCENE-7800.patch, LUCENE-7800.patch > > > For a long time I considered the "sneaky" throw hack to be a nice way of > coding around some of Java's limitations (especially with invoking methods > via reflection or method handles), but with time I started to see how it can > be potentially dangerous and is nearly always confusing. If you have a Java > method and its signature doesn't indicate the possibility of a checked > exception you, as a programmer, simply don't expect it to happen. Never. So, > for example, you could write: > {code} > try { > luceneApi(); > } catch (RuntimeException | Error e) { > // Handle unchecked exceptions here. > } > {code} > and consider the code above to be absolutely bullet-proof in terms of > handling exceptions. Unfortunately with sneaky throws anywhere in the > "luceneApi" this is no longer the case -- you can receive a checked exception > that will simply fall through and hit some code frame above. > So I suggest we remove sneaky throw from the core entirely. It only exists in > two places -- private methods inside Snowball programs invoked via method > handles (these don't even declare checked exceptions so I assume they can't > occur) and AttributeFactory -- here there is a real possibility somebody > could declare an attribute class's constructor that does throw an unchecked > exception. In that case I think it is more reasonable to wrap it in a > RuntimeException than rethrow it as original. > Alternatively, we can modify the signature of {{createAttributeInstance}} and > {{getStaticImplementation}} to declare some kind of checked exception (either > a wrapper or even a Throwable), but I see little reason for it and it'd > change the API. -- This message was sent by Atlassian JIRA (v6.3.15#6346) - To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org
[jira] [Updated] (LUCENE-7800) Remove code that potentially rethrows checked exceptions from methods that don't declare them ("sneaky throw" hack)
[ https://issues.apache.org/jira/browse/LUCENE-7800?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Dawid Weiss updated LUCENE-7800: Description: For a long time I considered the "sneaky" throw hack to be a nice way of coding around some of Java's limitations (especially with invoking methods via reflection or method handles), but with time I started to see how it can be potentially dangerous and is nearly always confusing. If you have a Java method and its signature doesn't indicate the possibility of a checked exception you, as a programmer, simply don't expect it to happen. Never. So, for example, you could write: {code} try { luceneApi(); } catch (RuntimeException | Error e) { // Handle unchecked exceptions here. } {code} and consider the code above to be absolutely bullet-proof in terms of handling exceptions. Unfortunately with sneaky throws anywhere in the "luceneApi" this is no longer the case -- you can receive a checked exception that will simply fall through and hit some code frame above. So I suggest we remove sneaky throw from the core entirely. It only exists in two places -- private methods inside Snowball programs invoked via method handles (these don't even declare checked exceptions so I assume they can't occur) and AttributeFactory -- here there is a real possibility somebody could declare an attribute class's constructor that does throw an unchecked exception. In that case I think it is more reasonable to wrap it in a RuntimeException than rethrow it as original. Alternatively, we can modify the signature of {{createAttributeInstance}} and {{getStaticImplementation}} to declare some kind of checked exception (either a wrapper or even a Throwable), but I see little reason for it and it'd change the API. > Remove code that potentially rethrows checked exceptions from methods that > don't declare them ("sneaky throw" hack) > --- > > Key: LUCENE-7800 > URL: https://issues.apache.org/jira/browse/LUCENE-7800 > Project: Lucene - Core > Issue Type: Task >Reporter: Dawid Weiss >Priority: Minor > Fix For: 6.x, master (7.0) > > Attachments: LUCENE-7800.patch > > > For a long time I considered the "sneaky" throw hack to be a nice way of > coding around some of Java's limitations (especially with invoking methods > via reflection or method handles), but with time I started to see how it can > be potentially dangerous and is nearly always confusing. If you have a Java > method and its signature doesn't indicate the possibility of a checked > exception you, as a programmer, simply don't expect it to happen. Never. So, > for example, you could write: > {code} > try { > luceneApi(); > } catch (RuntimeException | Error e) { > // Handle unchecked exceptions here. > } > {code} > and consider the code above to be absolutely bullet-proof in terms of > handling exceptions. Unfortunately with sneaky throws anywhere in the > "luceneApi" this is no longer the case -- you can receive a checked exception > that will simply fall through and hit some code frame above. > So I suggest we remove sneaky throw from the core entirely. It only exists in > two places -- private methods inside Snowball programs invoked via method > handles (these don't even declare checked exceptions so I assume they can't > occur) and AttributeFactory -- here there is a real possibility somebody > could declare an attribute class's constructor that does throw an unchecked > exception. In that case I think it is more reasonable to wrap it in a > RuntimeException than rethrow it as original. > Alternatively, we can modify the signature of {{createAttributeInstance}} and > {{getStaticImplementation}} to declare some kind of checked exception (either > a wrapper or even a Throwable), but I see little reason for it and it'd > change the API. -- This message was sent by Atlassian JIRA (v6.3.15#6346) - To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org
[jira] [Updated] (LUCENE-7800) Remove code that potentially rethrows checked exceptions from methods that don't declare them ("sneaky throw" hack)
[ https://issues.apache.org/jira/browse/LUCENE-7800?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Dawid Weiss updated LUCENE-7800: Attachment: LUCENE-7800.patch Patch removing sneaky throw from attribute factory and snowball programs. > Remove code that potentially rethrows checked exceptions from methods that > don't declare them ("sneaky throw" hack) > --- > > Key: LUCENE-7800 > URL: https://issues.apache.org/jira/browse/LUCENE-7800 > Project: Lucene - Core > Issue Type: Task >Reporter: Dawid Weiss >Priority: Minor > Fix For: 6.x, master (7.0) > > Attachments: LUCENE-7800.patch > > -- This message was sent by Atlassian JIRA (v6.3.15#6346) - To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org
[jira] [Updated] (LUCENE-7800) Remove code that potentially rethrows checked exceptions from methods that don't declare them ("sneaky throw" hack)
[ https://issues.apache.org/jira/browse/LUCENE-7800?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Dawid Weiss updated LUCENE-7800: Fix Version/s: 6.x > Remove code that potentially rethrows checked exceptions from methods that > don't declare them ("sneaky throw" hack) > --- > > Key: LUCENE-7800 > URL: https://issues.apache.org/jira/browse/LUCENE-7800 > Project: Lucene - Core > Issue Type: Task >Reporter: Dawid Weiss >Priority: Minor > Fix For: 6.x, master (7.0) > > -- This message was sent by Atlassian JIRA (v6.3.15#6346) - To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org
[jira] [Updated] (LUCENE-7800) Remove code that potentially rethrows checked exceptions from methods that don't declare them ("sneaky throw" hack)
[ https://issues.apache.org/jira/browse/LUCENE-7800?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Dawid Weiss updated LUCENE-7800: Priority: Minor (was: Major) > Remove code that potentially rethrows checked exceptions from methods that > don't declare them ("sneaky throw" hack) > --- > > Key: LUCENE-7800 > URL: https://issues.apache.org/jira/browse/LUCENE-7800 > Project: Lucene - Core > Issue Type: Task >Reporter: Dawid Weiss >Priority: Minor > Fix For: master (7.0) > > -- This message was sent by Atlassian JIRA (v6.3.15#6346) - To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org
[jira] [Updated] (LUCENE-7800) Remove code that potentially rethrows checked exceptions from methods that don't declare them ("sneaky throw" hack)
[ https://issues.apache.org/jira/browse/LUCENE-7800?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Dawid Weiss updated LUCENE-7800: Fix Version/s: master (7.0) > Remove code that potentially rethrows checked exceptions from methods that > don't declare them ("sneaky throw" hack) > --- > > Key: LUCENE-7800 > URL: https://issues.apache.org/jira/browse/LUCENE-7800 > Project: Lucene - Core > Issue Type: Task >Reporter: Dawid Weiss >Priority: Minor > Fix For: master (7.0) > > -- This message was sent by Atlassian JIRA (v6.3.15#6346) - To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org
[jira] [Updated] (LUCENE-7800) Remove code that potentially rethrows checked exceptions from methods that don't declare them ("sneaky throw" hack)
[ https://issues.apache.org/jira/browse/LUCENE-7800?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Dawid Weiss updated LUCENE-7800: Summary: Remove code that potentially rethrows checked exceptions from methods that don't declare them ("sneaky throw" hack) (was: Remove ") > Remove code that potentially rethrows checked exceptions from methods that > don't declare them ("sneaky throw" hack) > --- > > Key: LUCENE-7800 > URL: https://issues.apache.org/jira/browse/LUCENE-7800 > Project: Lucene - Core > Issue Type: Task >Reporter: Dawid Weiss > Fix For: master (7.0) > > -- This message was sent by Atlassian JIRA (v6.3.15#6346) - To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org