Thread: Error I've never seen before.

Results 1 to 5 of 5
  1. #1 Error I've never seen before. 
    Registered Member
    Wiffles's Avatar
    Join Date
    Dec 2007
    Posts
    1,168
    Thanks given
    100
    Thanks received
    198
    Rep Power
    493
    Error:

    Code:
    Exception in thread "Thread-0" java.lang.StackOverflowError

    Code:
    Exception in thread "Thread-0" java.lang.StackOverflowError
            at java.net.PlainSocketImpl.socketBind(Native Method)
            at java.net.PlainSocketImpl.bind(Unknown Source)
            at java.net.ServerSocket.bind(Unknown Source)
            at java.net.ServerSocket.<init>(Unknown Source)
            at server.run(server.java:136)
            at server.run(server.java:188)
            at server.run(server.java:188)
    the 'at server.run(server.java:188)' goes on and on and on forever lol


    server.run line 136:

    Code:
    clientListener = new java.net.ServerSocket(serverlistenerPort, 1, bindAddr);
    server.run line 188:

    Code:
    }
    (end of void run)

    entire server.run:

    Code:
    public void run() {
        try {
    	shutdownClientHandler = false;
    	java.net.InetAddress bindAddr = java.net.InetAddress.getByName("69.19.14.29");
    	clientListener = new java.net.ServerSocket(serverlistenerPort, 1, bindAddr);
    	misc.println("Wolf Legacy has ben started on "+clientListener.getInetAddress().getHostAddress()+":" + clientListener.getLocalPort());
    	while(true) {
    	    java.net.Socket s = clientListener.accept();
    	    s.setTcpNoDelay(true);
    	    String connectingHost = s.getInetAddress().getHostName();
    	    boolean checkbanned = false;
    	    try {
    		BufferedReader in = new BufferedReader(new FileReader("./data/bannedips.txt"));
    		String data = null;
    		while ((data = in.readLine()) != null) {
    		    if (connectingHost.startsWith(data)){
    			checkbanned = true;
    		    }
    		}
    	    } catch (IOException e) {
    		System.err.println("The banned IPs file could not be accessed.");
    		checkbanned = false;
    	    }
    	    if(clientListener != null && checkbanned == false) {
    		    int Found = -1;
    		    for (int i = 0; i < MaxConnections; i++) {
    			if (Connections[i] == connectingHost) {
    			    Found = ConnectionCount[i];
    			    break;
    			}
    		    }
    		    if (Found < 3) {
    			playerHandler.newPlayerClient(s, connectingHost);
    		    } else {
    			s.close();
    		    }
    	    } else {
    		misc.println("Rejected "+connectingHost+":"+s.getPort());
    		s.close();
    	    }
    	}
        } catch(java.io.IOException ioe) {
    	if(!shutdownClientHandler) {
    	    misc.println("Port already in use! fucking idiot I THOUGHT YOU WERE SMARTER THAN THAT!!!");
    	    if (secondattempt) {
    	        serverlistenerPort++;
    		secondattempt = false;
    	    }
    	    else {
    		secondattempt = true;
    	    }
    	    run();
    	} else {
    	    misc.println("ClientHandler was shut down.");
    	}
        }
    }
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Jan 2008
    Posts
    2,340
    Thanks given
    20
    Thanks received
    575
    Rep Power
    1202
    Wrap the code around a try and catch to see what's causing the problem.

    Code:
            try {
                //yourcodehere
            } catch(StackOverflowError s) {
                System.out.println("Caught "+s);
                s.printStackTrace();
             }
    Don't actually use that to handle the error because that would be the worst way to handle a StackOverFlowError, just would probably help to see the error up front.

    Look at the stack trace that the StackOverflowError produces so you know where in your code it occurs and use it to figure out how to rewrite your code so that it doesn't call itself recuringly so that it won't happen again.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Wiffles's Avatar
    Join Date
    Dec 2007
    Posts
    1,168
    Thanks given
    100
    Thanks received
    198
    Rep Power
    493
    Thanks Lil Micheal,

    Btw Arkadian does anyone even look in help section?
    Reply With Quote  
     

  4. #4  
    Community Veteran


    Join Date
    Jan 2008
    Posts
    2,659
    Thanks given
    494
    Thanks received
    627
    Rep Power
    980
    You need to post the whole class.
    ~iKilem
    Reply With Quote  
     

  5. #5  
    Programmer, Contributor, RM and Veteran




    Join Date
    Mar 2007
    Posts
    5,147
    Thanks given
    2,656
    Thanks received
    3,731
    Rep Power
    5000
    The problem is you are continually calling that method in a loop.

    Essentially your code is like this:

    Code:
    public void run() {
        try {
            // do some stuff
        } catch(IOException ex) {
            run();
        }
    }
    That means the call stack keeps growing larger and eventually overflows, hence the exception.

    You need to fix whatever is throwing the IOException continually whenevr you keep retrying.
    .
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •