harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Loats (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-4961) SocketChannel.socket().getLocalPort() returns -1 from ServerSocketChannel
Date Wed, 17 Oct 2007 20:40:51 GMT
SocketChannel.socket().getLocalPort() returns -1 from ServerSocketChannel

                 Key: HARMONY-4961
                 URL: https://issues.apache.org/jira/browse/HARMONY-4961
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
         Environment: Reproduced on Windows XP SP2, on apache-harmony-jdk-r580985-windows-x86-32-snapshot
            Reporter: Phil Loats

The following testcase fails onthe Harmony M3 snapshot build.  
  On J2SE 5.0, the output is "myport is 4321"
  On Harmony M3 is "myport is -1"

It seems that SocketChannelImpl.isBound flag remains false when accessed from
SocketChannelImpl$SocketAdapter.isBound() from

We need this fix in an IBM product, I'd be most helpful if any fix can be clearly identified
in SVN (i.e. don't lump other fixes with this fix).

=========simplified testcase===============

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class Test implements Runnable {
	public static void main(String[] args) {
		new Test().test();
	void test() {	
		new Thread(this).start();
	    try {
	        // Create a non-blocking server socket channel on port
	        ServerSocketChannel ssChannel = ServerSocketChannel.open();
	        int port = 4321;
	        ssChannel.socket().bind(new InetSocketAddress(port));

	        // Accept the connection request
	        SocketChannel sChannel = ssChannel.accept();
	        if (sChannel != null) {
	            int myport = sChannel.socket().getLocalPort();
	            System.out.println("myport is "+myport);
	    } catch (IOException e) {

	public void run() {
		try {
			Socket socket = new Socket(InetAddress.getByName("localhost"), 4321);
		    BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		    String str;
	        while ((str = rd.readLine()) != null) {
		} catch (Exception e) {

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message