Skip to content
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

SI-9113 Converting null collection Java<->Scala yields null #4343

Merged
merged 1 commit into from
Feb 23, 2015

Conversation

adriaanm
Copy link
Contributor

Originally submitted for 2.11.x in #4267

scala.collection.{JavaConversions, JavaConverters} no longer wrap
a null collection, but return null instead. Before, a wrapper would
hold the original null collections, delaying the NPE until the first
operation on the collection was called, with no way of knowing whether we
were holding such a time bomb wrapper until the NPE was thrown.

For example, this now holds: (null : java.util.Iterator[_]).asScala == null.
Before, a wrapper would silently be created that would NPE on any further interaction.

An example of this issue in the wild can be seen at
scalafx/scalafx#178, and an example of code
that generates such a wrapper [before the issue was fixed](https://github.com/scalafx/scalafx/blob/ad60d5faee687b71d3c0474510d
3f3dd081ea351/scalafx/src/main/scala/scalafx/stage/FileChooser.scala#L138).

`scala.collection.{JavaConversions, JavaConverters}` no longer wrap
a `null` collection, but return `null` instead. Before, a wrapper would
hold the original `null` collections, delaying the NPE until the first
operation on the collection was called, with no way of knowing whether we
were holding such a time bomb wrapper until the NPE was thrown.

For example, this now holds: `(null : java.util.Iterator[_]).asScala ==
null`. Before, a wrapper would silently be created that would NPE on any
further interaction.

An example of this issue in the wild can be seen at
scalafx/scalafx#178, and an example of code
that generates such a wrapper [before the issue was fixed](https://github.com/scalafx/scalafx/blob/ad60d5faee687b71d3c0474510d
3f3dd081ea351/scalafx/src/main/scala/scalafx/stage/FileChooser.scala#L138).
@Ichoran
Copy link
Contributor

Ichoran commented Feb 21, 2015

LGTM. Slightly more tests than strictly needed, but they should be fast so this isn't a problem.

@adriaanm
Copy link
Contributor Author

Thank you, @RomanHargrave, for addressing this! Let's merge this and follow up for the other wrappers (tracked by https://issues.scala-lang.org/browse/SI-9176)

adriaanm added a commit that referenced this pull request Feb 23, 2015
SI-9113 Converting `null` collection Java<->Scala yields `null`
@adriaanm adriaanm merged commit d3a1e72 into scala:2.12.x Feb 23, 2015
@adriaanm adriaanm deleted the reword-4267 branch August 5, 2015 01:30
@adriaanm adriaanm added the 2.12 label Oct 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants