I hava a project on github that is analysed by codacy . The analysis suggest to "Avoid using null" for the following line of code:
def doSomethingWithPath(path:Path) = {
require(path != null, "Path should not be null") //<-to avoid
...
}
What is the simplest scala idiomatic thing to do to fix it?
I would keep it as is. You aren't really using null here, just guarding against it. The alternative could be to just delete that line altogether, and decide to not handle the null at all. Ignoring the possibility of null might be fine in a well built code base where it shouldn't come up anyway and null would be a bug, but a simple guard to catch it could prevent more subtle bugs from showing up in case something went wrong and null actually happens.