ADDITIONAL SYSTEM INFORMATION :
System/OS :
Debian 9, 4.9.0-8-amd64 #1 SMP Debian 4.9.144-3.1 (2019-02-19) x86_64 GNU/Linux
Java :
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b01-1~deb9u1-b01)
OpenJDK 64-Bit Server VM (build 25.212-b01, mixed mode)
A DESCRIPTION OF THE PROBLEM :
In a JTextPane I put HTML with some images. Those images were previously put in the JTextPane images cache using "jTextPane.getDocument().putProperty("imageCache",cache)". It has been working fine for years, and works with Oracle JDK. But since OpenJDK 8 212 (may be on earlier releases too) it seems images get lost. It works randomly at the very beginning displaying some of the images, then if I refresh the component images are nor displayed anymore.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the below provided code with java version :
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b01-1~deb9u1-b01)
OpenJDK 64-Bit Server VM (build 25.212-b01, mixed mode)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Green arrow is displayed on all iterations.
ACTUAL -
With java version OpenJDK the green arrow is not displayed after a few iteration.
With java version Oracle Java(TM) SE Runtime Environment (build 1.8.0_172-b11) the green arrow in displayed on all iterations.
---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.Image;
import java.net.URL;
import java.util.Dictionary;
import java.util.Hashtable;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.text.EditorKit;
public class MainBug implements Runnable {
private static JFrame frame;
public static JPanel contentPanel;
static Dictionary<URL, Image> cache;
static JTextPane jTextPane;
static URL urlArrow;
public static void main(String[] args) {
try
{
urlArrow = new URL("http:\\arrow.png");
frame = new JFrame();
frame.setBounds(200, 200, 800, 600);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().setLayout(new BorderLayout(0, 0));
frame.setTitle("JTextPane HTML Images bug demo");
jTextPane = new JTextPane();
frame.getContentPane().add(contentPanel = new JPanel());
contentPanel.setLayout(new BorderLayout(0, 0));
contentPanel.add(jTextPane);
final EditorKit l_kit = jTextPane.getEditorKitForContentType("text/html");
jTextPane.setEditable(false);
jTextPane.setEditorKit(l_kit);
frame.getContentPane().add(jTextPane, BorderLayout.CENTER);
cache = (Dictionary<URL, Image>)jTextPane.getDocument().getProperty("imageCache");
if (cache==null) {
cache=new Hashtable<URL, Image>();
jTextPane.getDocument().putProperty("imageCache",cache);
}
Image l_greenequalImage = new ImageIcon(MainBug.class.getResource("arrow.png")).getImage().getScaledInstance(24, 24, java.awt.Image.SCALE_SMOOTH);
cache.put(urlArrow, l_greenequalImage);
frame.setVisible(true);
new Thread(new MainBug()).start();
}
catch(Exception e)
{
System.err.println(e);
e.printStackTrace();
}
}
public void run() {
for (int i=0; i < 5; i++)
{
jTextPane.setText("<html><body bgcolor=\"#666666\"><center>Iteration " + i + " -> <img src=\"" + urlArrow + "\"> </center></body></html>");
jTextPane.validate();
jTextPane.repaint();
try {
Thread.currentThread().sleep(2000);
} catch (InterruptedException e) { System.err.println(e); }
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use java version:
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
FREQUENCY : always