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

JEditorPane function setPage leaves a file lock

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 9
    • 8u66, 9
    • client-libs
    • b124
    • x86
    • windows_8

    Backports

      Description

        FULL PRODUCT VERSION :
        java version "1.8.0_66"

        A DESCRIPTION OF THE PROBLEM :
        When JEdiotPane.setPage is used with a file-Url, a file lock persists.
        The setPage function calls internal the function read(InputStream in, Document doc). The read function instantiates an InputStream - this inputstream will never be closed.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        File myFile = new File("ATextFile);
        JEditorPane myEditorPane = new JEditorPane();
        myEditorPane.setPage(myFile.toURI().toURL());

        after this the ATextFile has a file lock until the java program has been closed.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        After using setPage with a file-Url in my expection the file lock should be unlocked after reading the file.
        ACTUAL -
        The file lock persists, even when the file has been readen.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        File myFile = new File("ATextFile);
        JEditorPane myEditorPane = new JEditorPane();
        myEditorPane.setPage(myFile.toURI().toURL());

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

        CUSTOMER SUBMITTED WORKAROUND :
        The read-function in JEditorPane has private access. There is no way to to extend the JEditorPane.
        -< create an own class copy and merge the code of the setPage- and read-function and use:

        URL myUrl = p_TextFile.toURI().toURL();
        URLConnection myURLConnection = o_Url.openConnection();
        InputStream myInputStream = o_URLConnection.getInputStream();

        String charset = (String) myEditorPanegetClientProperty("charset");
        Reader r = (charset != null) ? new InputStreamReader(myInputStream, charset) :
        new InputStreamReader(myInputStream);
        myEditorPane.getEditorKit().read(r, myEditorPane.getDocument(), 0);

        ...

        //after all close the myInputStream
        myInputStream.close();


        Attachments

          Issue Links

            Activity

              People

                rchamyal Rajeev Chamyal (Inactive)
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: