url.openStream() bug??

Posted on 2001-07-24
Last Modified: 2011-10-03
Hello everybody,
I wrote a program that needs a connection to the internet to download some files in order to work properly.  The program periodically attempts to download the files opening a stream to the server using url.openStream(), if an exception occur, the program waits a period of time and then attempts again the connection.

I don't understand why it is behaving different depending on whether the dial-up connection is stablished or not.  If the connection is stablished before the program runs, everithing goes right, but if the program runs before the connection is stablished(at least 1 failed attempt was made for downloading the files) the url.openStream() always thows an exception no matters if the connection is available later on.

It seems to be like it "remembers" that the connection was unavailable and the next time it tries to download the files a real attempt is not made.
Maybe something is happening with the ip address, because it is assigned dinamically by the ISP and in the first case the ip address exists but in the second not until the connection is stablished.

Please, i need a solution as soon as possible.
Diego Broos V.
Question by:dbroos
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 6313594
Could you post the snippet of code which does this?  I think perhaps you are creating/calling the method in an inappropriate place and it's not getting reinitialized somehow...

(BTW, the word is established, not stablished.  I know many people on here have English as a second language, so no disrespect is meant in the correction...)


Author Comment

ID: 6315665
ok and thanks for the correction...

Here is the code:

public class CheckFile implements Runnable {
    public void run() {
        while (!stop) {
            try {
            } catch (Exception e){
                try {
                } catch(Exception ex) {}


    private void getData() throws Exception {
        BufferedInputStream bis = null;
        URL url = null;

        try {
            url = new URL(strurl);
            bis = new BufferedInputStream(url.openStream());
  , 0, arr.length);
        } catch(Exception e) {
            throw e;
        } finally {
            if(bis != null)
                try {
                } catch(Exception e) {}

Expert Comment

ID: 6315745
A suggestion is to either step through in debug or put in some output statements to see if you are hitting the exception on the "try" or the "finally" in your getData() method.  I suspect it has something to do with the bis.close() in the already connected instance, and the url.openStream() in the not connected instance.

See where the exception is being throws in each instance and we'll work from there...

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

LVL 10

Expert Comment

ID: 6315923

Accepted Solution

Sasha_Mapa earned 70 total points
ID: 6316363
This is a known bug which has been fixed in Merlin (JDK 1.4) -

The bug is that InetAddress.getByName() caches not only positive results (host found) but also negative results (host not found).

Sasha Maryanovsky.

Expert Comment

ID: 6320690
Btw, it might work if you specify your server(s) by IP and not by hostname.

P.S. Thanks for the points.

Sasha Maryanovsky.

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
runtime exception 2 67
how to debug htl and js pages 8 80
Find out all repos that a user is most active on Github 1 58
Java array 10 89
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question