harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vasily Zakharov (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-3453) [classlib][swing] JEditorPane.registerEditorKitForContentType(String, String, null) doesn't throw NPE
Date Fri, 30 Mar 2007 14:48:25 GMT

    [ https://issues.apache.org/jira/browse/HARMONY-3453?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12485518
] 

Vasily Zakharov commented on HARMONY-3453:
------------------------------------------

Hmm, good concern, thanks Alexey. I've investigated this question, here's the test:

import javax.swing.JEditorPane;

public class Test {
    public static void main(String args[]) throws Exception {
        System.out.println(JEditorPane.createEditorKitForContentType("testContentType1"));

        try {
            JEditorPane.registerEditorKitForContentType("testContentType1", "MyEditorKit",
null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(JEditorPane.createEditorKitForContentType("testContentType1"));
        System.out.println(JEditorPane.createEditorKitForContentType("testContentType1"));
        JEditorPane.registerEditorKitForContentType("testContentType2", "MyEditorKit");
        System.out.println(JEditorPane.createEditorKitForContentType("testContentType2"));
        System.out.println(JEditorPane.createEditorKitForContentType("testContentType2"));
    }
}

import java.io.*;
import javax.swing.*;
import javax.swing.text.*;

public class MyEditorKit extends EditorKit {

    public Object clone() {
        Object ret = super.clone();
        System.out.println("clone() of " + this + " returning: " + ret);
        return ret;
    }

    public Caret createCaret() { return null; }
    public Document createDefaultDocument() { return null; }
    public Action[] getActions() { return null; }
    public String getContentType() { return null; }
    public ViewFactory getViewFactory() { return null; }
    public void read(InputStream in, Document doc, int pos) {}
    public void read(Reader in, Document doc, int pos) {}
    public void write(OutputStream out, Document doc, int pos, int len) {}
    public void write(Writer out, Document doc, int pos, int len) {}
} 

Output on RI:

null
java.lang.NullPointerException
        at java.util.Hashtable.put(Unknown Source)
        at javax.swing.JEditorPane.registerEditorKitForContentType(Unknown Source)
        at Test.main(Test.java:7)
clone() of MyEditorKit@110b053 returning: MyEditorKit@a83b8a
MyEditorKit@a83b8a
clone() of MyEditorKit@110b053 returning: MyEditorKit@dd20f6
MyEditorKit@dd20f6
clone() of MyEditorKit@19efb05 returning: MyEditorKit@723d7c
MyEditorKit@723d7c
clone() of MyEditorKit@19efb05 returning: MyEditorKit@22c95b
MyEditorKit@22c95b

This test shows the following:
- It looks like RI keeps one EditorKit instance per content type (see the addresses at "clone()
of ...").
- It looks like RI calls clone() on that instance and returns that clone from createEditorKitForContentType().

EditorKit implements Clonable, so using clone() on EditorKit instances seems allowable. Also,
the specification for createEditorKitForContentType(EditorKit) states: "Once a prototype EditorKit
instance is successfully located, it is cloned and the clone is returned."

To me, all this looks reasonable enough to implement the instance caching per point 2 in my
previous comment.

If you agree and have no other objections, I'm proceeding with the patch. Thank you!


> [classlib][swing] JEditorPane.registerEditorKitForContentType(String, String, null) doesn't
throw NPE
> -----------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-3453
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3453
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib, Non-bug differences from RI
>            Reporter: Vasily Zakharov
>         Assigned To: Alexey Petrenko
>            Priority: Minor
>
> Consider the following test:
> import javax.swing.JEditorPane;
> public class Test {
>     public static void main(String args[]) throws Exception {
>         System.out.println(JEditorPane.createEditorKitForContentType("testContentType1"));
>         try {
>             JEditorPane.registerEditorKitForContentType("testContentType1", "MyEditorKit",
null);
>         } catch (Exception e) {
>             e.printStackTrace();
>         }
>         System.out.println(JEditorPane.createEditorKitForContentType("testContentType1"));
>         JEditorPane.registerEditorKitForContentType("testContentType2", "MyEditorKit");
>         System.out.println(JEditorPane.createEditorKitForContentType("testContentType2"));
>     }
> }
> public class MyEditorKit extends javax.swing.text.DefaultEditorKit {
> }
> Output on RI:
> null
> java.lang.NullPointerException
>         at java.util.Hashtable.put(Unknown Source)
>         at javax.swing.JEditorPane.registerEditorKitForContentType(Unknown Source)
>         at TestNPE.main(TestNPE.java:8)
> MyEditorKit@1a46e30
> MyEditorKit@3e25a5
> Output on Harmony:
> null
> null
> null
> The specification says nothing about passing null classloader.
> The NPE occurs on RI, and doesn't occur on Harmony, it seems that RI uses Hashtable (that
doesn't permit null keys/vaues) to store registered classloaders, and Harmony uses ArrayList.
> Also, as one may see, RI, besides throwing NPE, also registers the specified content
type anyway (compare createEditorKitForContentType results before and after registration attempt).
In my opinion, this behaviour is clearly a bug in RI. So my suggestion is to consider this
issue a non-bug difference.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message