Thursday, May 28, 2015

Today I learned... no @SuppressWarnings in Scala!

Today I learned something annoying... Scala does not have any way to suppress warnings on individual code elements.

In Java you can use the @SuppressWarnings attribute on a code element to suppress compiler warnings for that element. .NET has something similar with the [SuppressMessage] attribute. The point of it is if you've decided the compiler warning is not a problem in your scenario, you don't want to clutter up your compiler output. Ideally, you want to be able to treat warnings as errors and fail a build if you get a single warning -- so this prevents that if there are any legitimate warnings that you're unable to suppress.

For example, if you need to use a deprecated method in some third-party API, you might have done the research and gotten the code reviewed and decided it was ok. An example that I came across today was connectionCachingEnabled in OracleDataSource. (Fortunately, I ended up not needing to use it because I realized the default value is already "disabled" which is what I wanted anyway.)

I don't have a solution, unfortunately... Just an observation, and one that others have noted as well (and the Scala community has closed this feature request with "wontfix" -- see http://stackoverflow.com/questions/3506370/is-there-an-equivalent-to-suppresswarnings-in-scala).

No comments:

Post a Comment