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

(so) REGRESSION: bind throws an Error instead of BindException

    Details

    • Subcomponent:
    • Resolved In Build:
      b59
    • CPU:
      x86
    • OS:
      windows_2000

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      rebinding an already bound socket results an an Error: untranslated Exception being thrown instead of a BindException. This is a regression as this worked in one of the previous releases(I am not sure which release though).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run my JUnit test which binds an already bound socket to a different address.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      BindException should be thrown.
      ACTUAL -
      Error is thrown. Funny thing is the Errors chained exception is a sun AlreadyBoundException.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.Error: Untranslated exception
      at sun.nio.ch.Net.translateToSocketException(Net.java:63)
      at sun.nio.ch.Net.translateException(Net.java:79)
      at sun.nio.ch.Net.translateException(Net.java:85)
      at sun.nio.ch.SocketAdaptor.bind(SocketAdaptor.java:129)
      at biz.xsoftware.test.nio.suns.TestBindError.testBindError(TestBindError.java:71)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at junit.framework.TestCase.runTest(TestCase.java:165)
      at junit.framework.TestCase.runBare(TestCase.java:130)
      at junit.framework.TestResult$1.protect(TestResult.java:106)
      at junit.framework.TestResult.runProtected(TestResult.java:124)
      at junit.framework.TestResult.run(TestResult.java:109)
      at junit.framework.TestCase.run(TestCase.java:120)
      at junit.framework.TestSuite.runTest(TestSuite.java:210)
      at junit.framework.TestSuite.run(TestSuite.java:205)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
      Caused by: java.net.SocketException: Already bound
      at sun.nio.ch.Net.translateToSocketException(Net.java:49)
      ... 19 more
      Caused by: sun.nio.ch.AlreadyBoundException
      at sun.nio.ch.SocketChannelImpl.bind(SocketChannelImpl.java:412)
      at sun.nio.ch.SocketAdaptor.bind(SocketAdaptor.java:127)
      ... 16 more



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
       * Created on May 1, 2004
       *
       * To change the template for this generated file go to
       * Window - Preferences - Java - Code Generation - Code and Comments
       */
      package biz.xsoftware.test.nio.suns;

      import java.net.InetAddress;
      import java.net.InetSocketAddress;
      import java.nio.channels.SocketChannel;
      import java.util.logging.Logger;

      import junit.framework.TestCase;

      /**
       * Internal Review ID:
       *
       * This test proves the jdk throws an Error when it should be throwing a
       * normal Exception.
       *
       * TODO: need to write test to get binding to port 0 and see on linux if
       * it returns the port instead of 0 with getLocalPort.
       */
      public class TestBindError extends TestCase {

      private final static Logger log = Logger.getLogger(TestBindError.class.getName());


      /**
      * @param name
      */
      public TestBindError(String name) {
      super(name);
      }

      public void setUp() {

      }

      public void tearDown() {

      }

      public void testBindError() throws Exception {
      InetAddress loopBack = InetAddress.getByName("127.0.0.1");
      SocketChannel chan1 = SocketChannel.open();
      chan1.configureBlocking(false);

      InetSocketAddress addr1 = new InetSocketAddress(loopBack, 10000);
      InetSocketAddress addr2 = new InetSocketAddress(loopBack, 9999);
      chan1.socket().bind(addr1);
      //NOTE: At home I keep the try catch so my test passes until the bug is fixed. This
      //way, when I upgrade to a new jdk and some tests fail, I get happy :) and get rid of
      //these try catchs that exist at home.
      // try {
      chan1.socket().bind(addr2);
      // fail("Should have thrown untranslated exception Error");
      // } catch(Error e) {
      // //gulp
      // }
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      catch Errors in client code which should usually never be done.

      Release Regression From : 1.4.2_08
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sherman Xueming Shen
                Reporter:
                ndcosta Nelson Dcosta (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: