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

CSSParser falls back to Web.color for standard JavaFX CSS properties causing excessive exception handling on JavaApplicationThread

XMLWordPrintable

    • x86_64
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_151"
      Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Non-OS specific

      A DESCRIPTION OF THE PROBLEM :
      CSSParser appears to not correctly handle some standard JavaFX CSS properties properly and falls back to parsing a color for rather odd strings. This fall back means that in our case 1000s of exceptions occur on the JavaApplicationThread and have a minor perf impact. The color parsing code is here where the exception is IllegalArgumentException.

       // Assumes string is not a lookup!
          private ParsedValueImpl<Color,Color> colorValueOfString(String str) {

              if(str.startsWith("#") || str.startsWith("0x")) {

                  double a = 1.0f;
                  String c = str;
                  final int prefixLength = (str.startsWith("#")) ? 1 : 2;

                  final int len = c.length();
                  // rgba or rrggbbaa - trim off the alpha
                  if ( (len-prefixLength) == 4) {
                      a = Integer.parseInt(c.substring(len-1), 16) / 15.0f;
                      c = c.substring(0,len-1);
                  } else if ((len-prefixLength) == 8) {
                      a = Integer.parseInt(c.substring(len-2), 16) / 255.0f;
                      c = c.substring(0,len-2);
                  }
                  // else color was rgb or rrggbb (no alpha)
                  return new ParsedValueImpl<Color,Color>(Color.web(c,a), null);
              }

              try {
                  return new ParsedValueImpl<Color,Color>(Color.web(str), null);
              } catch (final IllegalArgumentException e) {
              } catch (final NullPointerException e) {
              }

              // not a color
              return null;
          }

      For example.
      For us setting -fx-alignment on a Vbox/Hbox appears to end in an exception throw + swallow for color 'center'. -fx-shape exhibits the same behavior.

      The CSSParser handles most types explicitly in the below method but not all.

      ParsedValueImpl valueFor(String property, Term root, CSSLexer lexer) throws ParseException {

      There is no negative side effects for style application only minor effects for perf with the high number of exceptions occurring.

      It would be great to handle these properties correctly without the overhead of exception handling.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Utilize particular and documented supported css properties such as -fx-alignment, -fx-shape in CSS file.

      Via Mission Control you can see the exceptions via profiling.

      Set a break point in CSSParser to see the property type that was being parsed.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No exceptions for standard JavaFX CSS properties.
      ACTUAL -
      Lots of exceptions.

      REPRODUCIBILITY :
      This bug can be reproduced always.

            angorya Andy Goryachev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: