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

Rendering HTML with empty img attribute and documentBaseKey cause Exception

    XMLWordPrintable

Details

    • b26
    • x86_64
    • windows_10

    Backports

      Description

        ADDITIONAL SYSTEM INFORMATION :
        Processor Intel(R) Xeon(R) CPU E5-2683 v4 @ 2.10GHz, 2095 Mhz, 2 Core(s), 2 Logical Processor(s)
        System Type x64-based PC

        OS Name Microsoft Windows 10 Enterprise
        Version 10.0.15063 Build 15063

        java version "1.8.0_221"
        Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
        Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)

        A DESCRIPTION OF THE PROBLEM :
        Rendering a Label using HTML text cause an NullPointerException when:
        - The img attribute is empty e.g. "<html><img src=''/></html>"
        - and the JComponent has a custom image base URL (BasicHTML.documentBaseKey)



        REGRESSION : Last worked in version 8u221

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        - Create a javax.swing.JLabel
        - Set a custome BasicHTML.documentBaseKey URL for the JLabel using putClientProperty
        - Set a HTML as text via setText("<html><img src=''/></html>")

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The configured ImageView.MISSING_IMAGE (html.missingImage) is rendered
        ACTUAL -
        A java.lang.NullPointerException is thrown see below:


        Stacktrace:
        at javax.swing.text.html.ImageView.updateImageSize(Unknown Source)
        at javax.swing.text.html.ImageView.refreshImage(Unknown Source)
        at javax.swing.text.html.ImageView.sync(Unknown Source)
        at javax.swing.text.html.ImageView.getPreferredSpan(Unknown Source)
        at javax.swing.text.FlowView$LogicalView.getPreferredSpan(Unknown Source)
        at javax.swing.text.FlowView.calculateMinorAxisRequirements(Unknown Source)
        at javax.swing.text.ParagraphView.calculateMinorAxisRequirements(Unknown Source)
        at javax.swing.text.html.ParagraphView.calculateMinorAxisRequirements(Unknown Source)
        at javax.swing.text.BoxView.checkRequests(Unknown Source)
        at javax.swing.text.BoxView.getMinimumSpan(Unknown Source)
        at javax.swing.text.html.ParagraphView.getMinimumSpan(Unknown Source)
        at javax.swing.text.BoxView.calculateMinorAxisRequirements(Unknown Source)
        at javax.swing.text.html.BlockView.calculateMinorAxisRequirements(Unknown Source)
        at javax.swing.text.BoxView.checkRequests(Unknown Source)
        at javax.swing.text.BoxView.getMinimumSpan(Unknown Source)
        at javax.swing.text.html.BlockView.getMinimumSpan(Unknown Source)
        at javax.swing.text.BoxView.calculateMinorAxisRequirements(Unknown Source)
        at javax.swing.text.html.BlockView.calculateMinorAxisRequirements(Unknown Source)
        at javax.swing.text.BoxView.checkRequests(Unknown Source)
        at javax.swing.text.BoxView.getPreferredSpan(Unknown Source)
        at javax.swing.text.html.BlockView.getPreferredSpan(Unknown Source)
        at javax.swing.plaf.basic.BasicHTML$Renderer.<init>(Unknown Source)
        at javax.swing.plaf.basic.BasicHTML.createHTMLView(Unknown Source)
        at javax.swing.plaf.basic.BasicHTML.updateRenderer(Unknown Source)
        at javax.swing.plaf.basic.BasicLabelUI.propertyChange(Unknown Source)
        at java.beans.PropertyChangeSupport.fire(Unknown Source)
        at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
        at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
        at java.awt.Component.firePropertyChange(Unknown Source)
        at javax.swing.JLabel.setText(Unknown Source)
        at SwingApp.initialize(SwingApp.java:32)
        at SwingApp.<init>(SwingApp.java:21)
        at SwingApp.main(SwingApp.java:13)


        ---------- BEGIN SOURCE ----------
        import java.awt.BorderLayout;
        import java.net.URL;

        import javax.swing.JFrame;
        import javax.swing.JLabel;
        import javax.swing.plaf.basic.BasicHTML;

        public class SwingApp {
            private JFrame frame;

            public static void main(String[] args) {
                try {
                 SwingApp window = new SwingApp();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            public SwingApp() {
                initialize();
            }

            private void initialize() {
                frame = new JFrame();
                frame.setBounds(100, 100, 450, 300);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                
                // This Label cause an exception
                try {
        JLabel broken = new JLabel();
        broken.putClientProperty(BasicHTML.documentBaseKey, new URL("https://www.google.com/"));
        broken.setText("<html><img src=''/></html>");
        frame.add(broken, BorderLayout.EAST);
                } catch (Exception ex) {
                 ex.printStackTrace();
                }
                frame.add(new JLabel("Test"), BorderLayout.CENTER);
                frame.add(new JLabel("<html><img src=''/></html>"), BorderLayout.WEST);
            }
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        No workaround known

        FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

                pbansal Pankaj Bansal (Inactive)
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: