-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Throw FileNotFoundException in Source.fromResource #8443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I think the CLA submission is manually approved. Signed it just now. The CLA check is not yet verified. |
This is a potentially breaking change - should it go to 2.14? Or do we consider it a bugfix? |
@lrytz Currently it NPEs. This just explicitly throws an exception containing the argument, so I think it's bug improvement. |
@nogurenn Thanks for the contribution! |
At the office, we were joking about an improvement to throw |
@som-snytt https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ClassLoader.html#getResourceAsStream(java.lang.String) says that it will return " If the original method threw an exception, I agree that the original exception should be preserved as a In general, it might be an interesting analysis to check all Java call sites and see if we're doing proper null checking, especially in scala-library. |
If I had a blog, I would already have posted something about all the stuff @lrytz does. I was thinking how he's been doing reviews and also the recent super call PR. The previous comment is a typical @lrytz contribution on the order of, I'm not above helping you figure out some stuff. This is my new favorite "javaism":
|
it got me soooo close to a destructive gesture against my laptop... thankfully @retronym's status on our slack reminded me that i'm not alone: |
That should be automatically added to the scaladoc of getters for constructor arguments annotated with |
|
If we were doing this API from scratch we'd probably return an |
resources aren't files; |
Why is it "source from resource". You'd think the re-source would come from a source. Maybe |
Ah, I see. ( |
I take it we're still going for |
yes, that seems to be the consensus-except-for-me :-) |
we usually ask for test coverage, but this seems like such a straightforward change I wouldn't insist on it. I assume you've tested it manually? |
Not to be nihlistic, but the method doesn't return a |
I agree. A test could probably be added to @Test(expected = classOf[java.io.FileNotFoundException])
def loadFromMissingResource(): Unit = {
Source.fromResource("missing.txt")
} The commits need to be squashed to one and given an appropriate commit message. The only procedural question I have is: If this is a bug, maybe this should be fixed in 2.12, as well? |
Meh, it's so late in the 2.12.x series, I think it's better to err on the side of stability, leaving existing behaviors unchanged unless they are blatantly incorrect. |
There is a facility:
Could also get a tmp file name, to ensure that it really doesn't exist. |
Here's what I tried. I looked for a random file inside src and tried it within the project sbt scala console. Is everything as expected here? scala> Source.fromResource("rootdoc.txt")
res2: scala.io.BufferedSource = <iterator>
scala> Source.fromResource("rootdoc.tx")
java.io.FileNotFoundException: resource 'rootdoc.tx' was not found
at scala.io.Source$.fromResource(Source.scala:181)
... 29 elided |
Would it help to adjust the error message to |
Fixes scala/bug#11743
Commits this comment quip. The quip makes sense to me. Just two questions.
IllegalArgumentException
be okay overFileNotFoundException
?