Gabriel95 / scalafx

Automatically exported from code.google.com/p/scalafx
Other
0 stars 0 forks source link

ScalaFX and null references #78

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The scalafx.scene.paint.PhongMaterial class has an auxiliary constructor that 
takes a number of Image arguments. However, its common for some, if not all, of 
these arguments (when passed to JavaFX) to be null.

Unfortunately, if null is actually passed as an argument for an Image reference 
to this constructor, ScalaFX will throw a NullPointerException when 
dereferencing the delegated Image (in the implicit conversion function 
scalafx.scene.image.Image.sfxImage2jfx).

The workaround is to modify the PhongMaterial properties directly using the 
default constructor. That is, instead of:

new PhongMaterial (Color.RED, someImage, null, null, null)

you would use:

new PhongMaterial () {
  diffuseColor = Color.RED
  diffuseMap = someImage
}

A more Scala-friendly version would likely take Option[Image] arguments instead 
of Image arguments, passing the delegated image (if Some) or null (if None) to 
JavaFX.

However, there's also the issue of retrieving image references from JavaFX that 
can result in the same issue, since the default value for the various image map 
values is null too. In this case, the implicit conversion function 
scalafx.beans.property.ObjectProperty.sfxObjectProperty2jfx will throw a 
NullPointerException when attempting to pass the delegated image value back to 
JavaFX.

It seems that this is a general problem throughout ScalaFX were null references 
are possible, and the solution is neither trivial nor without side-effects.

Original issue reported on code.google.com by mike@hindsight-consulting.com on 5 Sep 2013 at 3:13

GoogleCodeExporter commented 8 years ago
Actually, I'm not sure about the null property values being an issue - that is 
likely OK (since the delegated value will be null and can be retrieved as 
such). It is only an issue when a ScalaFX delegated type has the value null.

Apologies for the confusion.

Original comment by mike@hindsight-consulting.com on 5 Sep 2013 at 3:18