Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8289587

IllegalArgumentException: Color.rgb's red parameter (-16776961) expects color values 0-255

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • jfx19
    • jfx11.0.11, 8u291, jfx17, jfx18
    • javafx
    • web

    Backports

      Description

        Calling the WebKit's ChooseColor component from a WebView like:

        WebView web = new WebView();
        web.getEngine().loadContent("<head></head><body><input type=\"color\" value=\"#000000\"></body>");

        fails with the exception:

        Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Color.rgb's red parameter (-16776961) expects color values 0-255
                at javafx.graphics@19-internal/javafx.scene.paint.Color.checkRGB(Color.java:232)
                at javafx.graphics@19-internal/javafx.scene.paint.Color.rgb(Color.java:179)
                at javafx.web@19-internal/com.sun.webkit.ColorChooser.fwkCreateAndShowColorChooser(ColorChooser.java:71)
                at javafx.web@19-internal/com.sun.webkit.WebPage.twkProcessMouseEvent(Native Method)
                at javafx.web@19-internal/com.sun.webkit.WebPage.dispatchMouseEvent(WebPage.java:843)
                at javafx.web@19-internal/javafx.scene.web.WebView.processMouseEvent(WebView.java:1098)


        It works fine since JavaFX 11 up until 16, starts failing with any JavaFX 17+ and LTS JavaFX 11.0.11+.

        This narrows it down to JDK-8259635, where the changes to version 610.2 of WebKit added a few changes in all related Color classes.

        In particular, in ColorChooserJava.cpp, the call to fwkCreateAndShowColorChooser changed from using
        color.red(), color.green(), color.blue(), to use the constants color.red, color.green, color.blue, which are defined as:

        static constexpr auto red = SRGBA<uint8_t> { 255, 0, 0 };
        static constexpr auto green = SRGBA<uint8_t> { 0, 255, 0 };
        static constexpr auto blue = SRGBA<uint8_t> { 0, 0, 255 };
            
        Therefore, not only the conversion from SRGBA to int passes always the same three values:
        r = -16776961, g = -16711936, b = -65536
        to fwkCreateAndShowColorChooser in ColorChooser.java, no matter the "value" set in the html input, but also it throws the above exception, as these three values are out of range for Color.rgb(r, g, b);

        Attachments

          Issue Links

            Activity

              People

                jpereda Jose Pereda
                jpereda Jose Pereda
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: