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

CSS LengthUnit doesn't parse %-values

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10 (1809)
      java version "11.0.5" 2019-10-15 LTS
      Java(TM) SE Runtime Environment 18.9 (build 11.0.5+10-LTS)
      Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      NumberFormatException is thrown for CSS font-size:
      font-size: 100%;

      The class CSS.FontSize (package javax.swing.text.html) supports %-values, however the method parse:2875, CSS$LengthUnit (javax.swing.text.html) has the "if" statement:

      2875: if (length > 0 && value.charAt(length - 1) == '%') {
                      try {
                          this.value = Float.valueOf(value.substring(0, length - 1)). floatValue() / 100.0f;
                          ...
                      }
                      catch (NumberFormatException nfe) { }
                  }
                  if (length >= 2) {
                  ...
      so, if we are able to parse "100%", the parsing is not interrupted, it goes further and fails with the exception

      REGRESSION : Last worked in version 8

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      parse CSS font-size value. E.g.
         font-size: 100%;

      if possible, please look at the implementation of the method parse in line 2875.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Parse the value without any exception
      ACTUAL -
      readJavaFormatString:2054, FloatingDecimal (jdk.internal.math)
      parseFloat:122, FloatingDecimal (jdk.internal.math)
      parseFloat:455, Float (java.lang)
      valueOf:419, Float (java.lang)
      parse:2914, CSS$LengthUnit (javax.swing.text.html)
      <init>:2867, CSS$LengthUnit (javax.swing.text.html)
      parseCssValue:2081, CSS$FontSize (javax.swing.text.html)
      getInternalCSSValue:839, CSS (javax.swing.text.html)
      addInternalCSSValue:824, CSS (javax.swing.text.html)
      addCSSAttribute:527, StyleSheet (javax.swing.text.html)
      handleValue:3342, StyleSheet$CssParser (javax.swing.text.html)
      parseDeclaration:358, CSSParser (javax.swing.text.html)
      parseDeclarationBlock:325, CSSParser (javax.swing.text.html)
      parseRuleSet:272, CSSParser (javax.swing.text.html)
      getNextStatement:178, CSSParser (javax.swing.text.html)
      parse:153, CSSParser (javax.swing.text.html)
      parse:3261, StyleSheet$CssParser (javax.swing.text.html)
      addRule:314, StyleSheet (javax.swing.text.html)
      createStyleSheet:89, JBHtmlEditorKit (com.intellij.util.ui)
      configureHtmlKitStylesheet:93, StartupUiUtil (com.intellij.util.ui)
      lambda$prepareAndStart$1:164, StartupUtil (com.intellij.idea)
      run:-1, 1760817729 (com.intellij.idea.StartupUtil$$Lambda$63)
      run:1736, CompletableFuture$AsyncRun (java.util.concurrent)
      dispatch:313, InvocationEvent (java.awt.event)
      dispatchEventImpl:776, EventQueue (java.awt)
      run:727, EventQueue$4 (java.awt)
      run:721, EventQueue$4 (java.awt)
      doPrivileged:-1, AccessController (java.security)
      doIntersectionPrivilege:85, ProtectionDomain$JavaSecurityAccessImpl (java.security)
      dispatchEvent:746, EventQueue (java.awt)
      pumpOneEventForFilters:203, EventDispatchThread (java.awt)
      pumpEventsForFilter:124, EventDispatchThread (java.awt)
      pumpEventsForHierarchy:113, EventDispatchThread (java.awt)
      pumpEvents:109, EventDispatchThread (java.awt)
      pumpEvents:101, EventDispatchThread (java.awt)
      run:90, EventDispatchThread (java.awt)

      CUSTOMER SUBMITTED WORKAROUND :
      don't use %

      FREQUENCY : always


        1. Main.java
          0.4 kB
        2. result.png
          result.png
          133 kB

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: