JDK-8008223 : java/net/BindException/Test.java fails rarely
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7,8
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2013-02-14
  • Updated: 2013-12-17
  • Resolved: 2013-03-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u21Fixed 8 b82Fixed
Description
ACTION: main -- Failed. Execution failed: `main' threw exception: java.lang.Exception: 1 t
ests(s) failed - see log
REASON: Assumed action based on file name: run main Test
TIME:   0.099 seconds
messages:
command: main Test
reason: Assumed action based on file name: run main Test
elapsed time (seconds): 0.099
STDOUT:

**************************
Test 12
DatagramSocket binds: /fe80:0:0:0:20c:29ff:fed7:b320%eth1 port: 42702
DatagramSocket binds: /fe80:0:0:0:20c:29ff:fed7:b320%eth1
No bind failure as expected - test failed!!!

12 test(s) executed. 1 failure(s).
STDERR:
java.lang.Exception: 1 tests(s) failed - see log
        at Test.main(Test.java:224)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.ja
va:43)
        at java.lang.reflect.Method.invoke(Method.java:487)
        at com.sun.javatest.regtest.MainAction$SameVMRunnable.run(MainAction.java:706)
        at java.lang.Thread.run(Thread.java:722)

JavaTest Message: Test threw exception: java.lang.Exception
JavaTest Message: shutting down test


TEST RESULT: Failed. Execution failed: `main' threw exception: java.lang.Exception: 1 test
s(s) failed - see log
--------------------------------------------------

Comments
This test has been around a long time, and rarely fails, but has had several bugs closed as 'not reproducible' marked against it. The test tries to verify that a BindException is thrown, or not thrown, in the appropriate circumstances. It does this by creating/binding a first socket to a specific socket address, then attempting to bind a second socket to possibly the same address. If the second socket attempts to bind to the same address as the first socket, then a BindException is expected to be thrown. The problem appears to be an issue with the test itself. A local variable holds a reference to the first socket. This local variable is never accessed again within its scope (or elsewhere), therefore becomes instantly unreachable and eligible for collection by the GC. The second socket, if binding with the same address, is expected to throw BindException, but the first socket is no longer guaranteed to be live and therefore the address is not guaranteed to be unbindable. I managed to reproduce the failure above, relatively consistently, by inserting 'System.runFinalization(); System.gc();' between the creation/binding of the first socket and the binding of the second one. This gives weight to the above analysis. The solution is to simply add some trivial statement that references the first socket, after the second one is bound. This will ensure that the first socket remains reachable until after the second socket attempts to bind.
14-02-2013