Abnaxos / meldioc

A prototype of an IoC (Inversion of Control) library for Java
MIT License
5 stars 1 forks source link

ExtensionPoint provision throwing checked exception causes compiler error #68

Closed Abnaxos closed 3 years ago

Abnaxos commented 4 years ago

When an extension point provision method throws a checked exception, this exception won't be declared in the generated setup method causing a compiler error.

Two possible fixes:

  1. IMHO, extension point provisions should not throw exceptions, it just doesn't make any sense. So, simply prohibiting extension point provisions that throw checked exceptions seems reasonable.

  2. Then again, maybe the user has some good reason – I can't think of a good reason, but who knows. Declaring that exception as being thrown when building the configuration is also a possibility.

I tend to go for 1, because extension point provisions are usually just accessors for final objects, i.e. compositions. That's how you implement extension points. They don't throw. Then again, does it hurt to allow it? After all, 2 is only insignificantly more complex than 1.

Going for 2 (see comments)

Abnaxos commented 3 years ago

I'm going for 2.

Yes, I consider it bad practice for a EP provision to throw an exception. But this is a compiler and it's not the compiler's job to impose what's good and bad practice, its job is to be consistent with the language. Since the language allows exceptions to be thrown from EP provisions, this case should to be handled correctly by the compiler.