JDK-8230235 : Rendering HTML with empty img attribute and documentBaseKey cause Exception
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8u221,11.0.4-oracle,13,14
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2019-08-16
  • Updated: 2021-01-12
  • Resolved: 2019-11-27
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 11 JDK 13 JDK 14 JDK 8 Other
11.0.7-oracleFixed 13.0.3Fixed 14 b26Fixed 8u251Fixed openjdk8u252Fixed
Related Reports
Relates :  
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



Comments
Fix request (13u) The patch applies perfectly, test works as expected before and after the fix.
25-03-2020

Approving for 8u252 as this is a regression in a recent release, but I see no reason why this didn't go in during the development phase of 8u252.
10-03-2020

Fix Request (OpenJDK 8u): Please approve backporting this to OpenJDK 8u252 as this fixes a regression introduced with JDK-8218674 (which is in 8u). It's a patch which we should include for Oracle JDK 8u251 parity. Additionally, it's a dependency for JDK-8224475 (also slated for 8u252). Included regression test fails without the patch passes after. The JDK 11u patch applies clean after path unshuffeling. If approved we should push the test fix JDK-8235744 with it.
09-03-2020

Fix Request (11u) This fixes the NPE in Swing, and keeps codebases in sync (I see 11.0.7-oracle). Patch applies cleanly to 11u, new test fails without the product fix, passes with it. Patched 11u passes tier1, tier2, tier3 (including headful) tests.
20-01-2020

URL: https://hg.openjdk.java.net/jdk/jdk/rev/1e563056dd3c User: psadhukhan Date: 2019-12-03 07:13:08 +0000
03-12-2019

URL: https://hg.openjdk.java.net/jdk/client/rev/1e563056dd3c User: pbansal Date: 2019-11-27 05:36:17 +0000
27-11-2019

Approved to push: http://mail.openjdk.java.net/pipermail/swing-dev/2019-November/009932.html
25-11-2019

This is a regression of https://bugs.openjdk.java.net/browse/JDK-8218674
30-09-2019

I am able to reproduce this with jdk1.8.0_231b98
03-09-2019

Reported as a regression in JDK 8u221, where Rendering HTML with empty img attribute and documentBaseKey cause Exception. Checked this with reported version and could confirm the issue. Result: ============= 8u211: OK 8u221: Fail 12.0.2: OK 13 ea b33: Fail 14 ea b11: Fail This seems a regresison introduced in 8u221 and does affect JDK 13 ea as well. To verify, run the attached test case with respective JDK version. Output with JDK 8u221: ======================= > java SwingApp java.lang.NullPointerException at javax.swing.text.html.ImageView.updateImageSize(ImageView.java:745) at javax.swing.text.html.ImageView.refreshImage(ImageView.java:676) at javax.swing.text.html.ImageView.sync(ImageView.java:645) at javax.swing.text.html.ImageView.getPreferredSpan(ImageView.java:443) at javax.swing.text.FlowView$LogicalView.getPreferredSpan(FlowView.java:732)
27-08-2019