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

InetAddress.isReachable returns true for a non-existing IP address

XMLWordPrintable

    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_102"
      Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
      Java HotSpot(TM) Client VM (build 25.102-b14, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      The fix to bug JDK-8159410 is not completely correct and still exhibits different behavior from 8u73. When a non-existing IP address with the same subnet as the machine is submitted to InetAddress.isReachable, 8u73 reports false consistently. However, 8u102 reports inconsistent results when the same test is repeated.

      REGRESSION. Last worked in version 8u92

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_73"
      Java(TM) SE Runtime Environment (build 1.8.0_73-b02)
      Java HotSpot(TM) Client VM (build 25.73-b02, mixed mode, sharing)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Execute the attached source.
      2. Enter a non-existing IP address with the same subnet as the computer in the text field.
      3. Press the Ping button multiple times and different results will be reported.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The method InetAddress.isReachable should return false for a non-existing IP address consistently.
      ACTUAL -
      InetAddress.isReachable returns inconsistent results in repeated tests.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.Cursor;
      import java.awt.Dimension;
      import java.io.IOException;
      import java.net.InetAddress;

      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JPanel;
      import javax.swing.JScrollPane;
      import javax.swing.JTextArea;
      import javax.swing.JTextField;

      public class TestPing extends JFrame {
          public TestPing() {
              setTitle(getClass().getSimpleName() + " " + System.getProperty("java.version"));
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              JTextArea textArea = new JTextArea();
              textArea.setEditable(false);
              JScrollPane scrollPane = new JScrollPane(textArea);
              scrollPane.setPreferredSize(new Dimension(400, 300));
              getContentPane().add(scrollPane, BorderLayout.CENTER);

              JPanel panel = new JPanel();
              getContentPane().add(panel, BorderLayout.NORTH);

              JLabel lblIpAddress = new JLabel("IP Address");
              panel.add(lblIpAddress);

              JTextField textField = new JTextField();
              panel.add(textField);
              textField.setColumns(11);

              JButton button = new JButton("Ping");
              panel.add(button);
              button.addActionListener(e -> {
                  try {
                      Cursor tfCursor = textField.getCursor();
                      textField.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                      setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                      InetAddress address = InetAddress.getByName(textField.getText());
                      boolean reachable = address.isReachable(5000);
                      textArea.append(address + " machine is " + (reachable ? "" : "NOT ") + "an active host\n");
                      textField.setCursor(tfCursor);
                      setCursor(Cursor.getDefaultCursor());
                  }
                  catch (IOException ex) {
                      textArea.append("Error: " + ex.getMessage() + "\n");
                  }
              });

              textField.addActionListener(e -> button.doClick());
          }

          public static void main(String[] args) {
              TestPing test = new TestPing();
              test.pack();
              test.setLocationRelativeTo(null);
              test.setVisible(true);
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use 8u73.

            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: