-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
5.0
-
x86
-
windows_xp
FULL PRODUCT VERSION :
1.5.0_09
ADDITIONAL OS VERSION INFORMATION :
Windows XP
EXTRA RELEVANT SYSTEM CONFIGURATION :
This bug looks the same one as
Bug ID: 4199915
Bug ID: 4123386
Also, javax.swing.text.html.HRuleView has this bug.
A DESCRIPTION OF THE PROBLEM :
I've compared the following source code (with my code investigation tool ;-):
javax.swing.text.html.ImageView.modelToView
javax.swing.text.html.HRuleView.modelToView
javax.swing.text.IconView.modelToView
javax.swing.text.ComponentVIew.modelToView
Apparently, the first two methods return null without throwing an exception.
On the other hand, the other two correctly throw an exception.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Put the sample.html and the pic.jpg to C:\temp (that is, C:\temp\sample.html and C:\temp.pic.jpg).
2) Compile and run the test.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A window titled "Test" will be shown and the console will say "Caught!".
ACTUAL -
The window is shown but the console says "Not Caught!".
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.html.*;
import javax.swing.text.*;
public class Test {
private static void trav(Element root) {
int count = root.getElementCount();
for (int i = 0; i < count; ++i) {
Element elem = root.getElement(i);
String name = elem.getName();
System.out.println(name);
if (name.equals("img")) {
ImageView iv = new ImageView(elem);
try {
Shape s = iv.modelToView(-1, null, null); // supposed to throw BadLocationException
System.err.println("Not Caught!");
}
catch (BadLocationException e) {
System.err.println("Caught!");
}
}
trav(elem);
}
}
public static void main(String args[]) {
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});
JEditorPane html = null;
try {
html = new JEditorPane("file:///c:/temp/sample.html");
} catch(Exception err) {
err.printStackTrace();
}
frame.getContentPane().add(new JScrollPane(html));
frame.setSize(400 , 400);
frame.setVisible(true);
DefaultStyledDocument doc = (DefaultStyledDocument)html.getDocument();
Element root = doc.getDefaultRootElement();
trav(root);
}
}
---------- END SOURCE ----------
REPRODUCIBILITY :
This bug can be reproduced rarely.
1.5.0_09
ADDITIONAL OS VERSION INFORMATION :
Windows XP
EXTRA RELEVANT SYSTEM CONFIGURATION :
This bug looks the same one as
Bug ID: 4199915
Bug ID: 4123386
Also, javax.swing.text.html.HRuleView has this bug.
A DESCRIPTION OF THE PROBLEM :
I've compared the following source code (with my code investigation tool ;-):
javax.swing.text.html.ImageView.modelToView
javax.swing.text.html.HRuleView.modelToView
javax.swing.text.IconView.modelToView
javax.swing.text.ComponentVIew.modelToView
Apparently, the first two methods return null without throwing an exception.
On the other hand, the other two correctly throw an exception.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Put the sample.html and the pic.jpg to C:\temp (that is, C:\temp\sample.html and C:\temp.pic.jpg).
2) Compile and run the test.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A window titled "Test" will be shown and the console will say "Caught!".
ACTUAL -
The window is shown but the console says "Not Caught!".
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.html.*;
import javax.swing.text.*;
public class Test {
private static void trav(Element root) {
int count = root.getElementCount();
for (int i = 0; i < count; ++i) {
Element elem = root.getElement(i);
String name = elem.getName();
System.out.println(name);
if (name.equals("img")) {
ImageView iv = new ImageView(elem);
try {
Shape s = iv.modelToView(-1, null, null); // supposed to throw BadLocationException
System.err.println("Not Caught!");
}
catch (BadLocationException e) {
System.err.println("Caught!");
}
}
trav(elem);
}
}
public static void main(String args[]) {
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});
JEditorPane html = null;
try {
html = new JEditorPane("file:///c:/temp/sample.html");
} catch(Exception err) {
err.printStackTrace();
}
frame.getContentPane().add(new JScrollPane(html));
frame.setSize(400 , 400);
frame.setVisible(true);
DefaultStyledDocument doc = (DefaultStyledDocument)html.getDocument();
Element root = doc.getDefaultRootElement();
trav(root);
}
}
---------- END SOURCE ----------
REPRODUCIBILITY :
This bug can be reproduced rarely.