JDK-8088925 : Non opaque background cause NumberFormatException
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 8u20,9,10
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-03-12
  • Updated: 2020-01-31
  • Resolved: 2018-01-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 Other
8u172Fixed openjfx11Fixed
Description
An editable DIV with non opaque background cause an exception when focused.
In HTMLEditorSkin.rgbToHex, the alpha value is handled like an integer but it is a float.
Comments
WebRev for backport to 8: http://cr.openjdk.java.net/~rkamath/8088925/webrev.backport.00/
08-01-2018

Changeset: 5a3cc1b5bb22 Author: rkamath Date: 2018-01-03 12:47 +0530 URL: http://hg.openjdk.java.net/openjfx/jfx-dev/rt/rev/5a3cc1b5bb22 8088925: Non opaque background cause NumberFormatException Reviewed-by: arajkumar, ghb
03-01-2018

+1
03-01-2018

+1
02-01-2018

Thanks [~ghb] Addressed both the changes suggested in http://cr.openjdk.java.net/~rkamath/8088925/webrev.01/
02-01-2018

+1, Note : fgColorButton.setValue(c); --> fgColorButton.setValue(getColor(foregroundColorValue)); // will reduce a local variable
01-01-2018

Yes [~arajkumar], using constants is better. Will make this change.
28-12-2017

lgtm with a nit: Probably using color constants will improve the readability. + if (color.toString().equals("0x00000000")) { + color = Color.web("#FFFFFFFF"); } if (color.equals(Color.TRANSPARENT)) { color = Color.WHITE; }
27-12-2017

NumberFormatException occurs because of trying to parse the floating point alpha value as an integer. In current code, method rgbToHex tries to parse rgba value and returns a hex. This would again be used to construct a Color object. In the patch, have changed the method name to getColor which will directly return a Color object. The task of parsing the requisite rgba values would be done by the Color object creation helpers internally.(which will also parse the alpha as double value thus solving the issue at hand) Request to review: http://cr.openjdk.java.net/~rkamath/8088925/webrev.00/
26-12-2017

Run the following code, click on the lower DIV and check the console. package javafx; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.BorderPane; import javafx.scene.web.HTMLEditor; import javafx.stage.Stage; /** * Demonstrate an issue with non opaque colors in the HTMLEditor */ public class HTMLEditorTest extends Application{ @Override public void start(Stage primaryStage) throws Exception { // Buid the scene HTMLEditor editor = new HTMLEditor(); BorderPane rootPane = new BorderPane(editor); Scene scene = new Scene(rootPane); // Show primaryStage.setScene(scene); primaryStage.sizeToScene(); primaryStage.show(); // Load some content // This is OK // String html = "<html><body><div contenteditable='true'>Some content</div></html>"; // This cause an exception when clicking in the div String html = "<html><head><style>" + ".non-opaque { " + "background-color: rgba(255, 0, 255, 0.3); " + "}" + ".plain-color { " + "background-color: rgb(255, 0, 255); " + "}" + "</style></head><body> " + "<div contenteditable='true' class='plain-color'>This part is opaque and cause no error.</div>" + "<div contenteditable='true' class='non-opaque'>This part is not opaque and cause an error.</div>" + "</html>"; editor.setHtmlText(html); } public static void main(String[] args) { launch(args); } }
12-03-2015