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

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

Closed
scabug opened this issue Jan 26, 2015 · 6 comments
Closed

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

scabug opened this issue Jan 26, 2015 · 6 comments

Comments

@scabug
Copy link

scabug commented Jan 26, 2015

When a null value is cast as a Java collection, and an implicit converter from scala.collection.convert.WrapAsScala is in scope, the converter will be passed null and return a wrapped collection with null as the underlying collection. Calling any bridge method provided by the wrapper will result in a NullPointerException. This can cause unexpected behavior in an application that relies on interacting with a wrapper collection, but does not have access to the underlying java reference in order to determine whether it is a collection or null. In this scenario, the application gets the collection wrapper via whatever means, and tries to operate upon it - thus generating a somewhat counter-intuitive exception.

An example of this issue in the wild can be seen at scalafx issue #178, and an example of code that generates such a wrapper before the issue was fixed.

@scabug
Copy link
Author

scabug commented Jan 26, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9113?orig=1
Reporter: @RomanHargrave
Affected Versions: 2.11.2, 2.11.4

@scabug
Copy link
Author

scabug commented Jan 26, 2015

@RomanHargrave said:
Added a test suite to demonstrate null conversion bug.

@scabug
Copy link
Author

scabug commented Jan 26, 2015

@RomanHargrave said:
I have opened pr #4266, which fixes this issue.

@scabug
Copy link
Author

scabug commented Jan 26, 2015

@RomanHargrave said:
The previous PR had some problems with jenkins, so I have closed it and opened #4267 in its place.

@scabug
Copy link
Author

scabug commented Feb 13, 2015

@adriaanm said:
Slight reword in scala/scala#4327

@scabug
Copy link
Author

scabug commented Feb 23, 2015

@adriaanm said:
scala/scala#4343

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants