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

HyperlinkEvent.getURL() returns null for #anchor links

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • None
    • 6u10
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.6.0_10"
      Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
      Java HotSpot(TM) 64-Bit Server VM (build 11.0-b15, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.0.6001]

      A DESCRIPTION OF THE PROBLEM :
      If a JEditorPane contains a link like "#target", clicking on it generates a HyperlinkEvent with a null URL.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the provided test program.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should print the same anchor which is found in the HTML text.
      ACTUAL -
      Actually prints null.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import javax.swing.JEditorPane;
      import javax.swing.JOptionPane;
      import javax.swing.event.HyperlinkEvent;
      import javax.swing.event.HyperlinkListener;

      import org.junit.Test;

      public class Test {
          public static void main(String[] args) {
              String message = "<html><p id='target'><a href='#target'>click me</a><p></html>");
              JEditorPane label = new JEditorPane("text/html", message);
              label.setEditable(false);
              label.addHyperlinkListener(new HyperlinkListener() {
                  public void hyperlinkUpdate(HyperlinkEvent event) {
                      System.out.println(event.getURL());
                  }
              });
              JOptionPane.showMessageDialog(null, label, "Click the link", JOptionPane.ERROR_MESSAGE);
          }
      }


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

      CUSTOMER SUBMITTED WORKAROUND :
      As long as you don't actually need the anchor you can just check for null before using the URL. If you need it, no idea.

            peterz Peter Zhelezniakov
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: