🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #594

The static method readURL(String) from the type URLReader should be accessed in a static way

#594
From: Scott Powell
Date: Tue, 22 Mar 2005 22:47
56 lines
2430 bytes
I get the cited warning message in a project I'm working on.

URLReader's signature is  public static String readURL(URL url)

And indeed the method that calls it is not static.

But I don't really understand why it would generate a warning or how one
could solve it.

The readURL method only uses local variables (and the parameter) so it
doesn't need to not be static (if I understand when static gets used).

Full method is below.

Thanks
Scott

 public static String readURL(URL url){
  StringBuffer sb = new StringBuffer();
  String s = "";
  InputStream is = null;
  BufferedInputStream bis = null;
  InputStreamReader isr = null;
  BufferedReader br = null;
  try{
   is = url.openStream();
   bis = new BufferedInputStream(is);
   isr = new InputStreamReader(bis);
   br = new BufferedReader(isr);
   do {
    s = br.readLine();
    if (s != null){
     sb.append(s);
    }
   } while (s != null);
  }catch (IOException e){
   System.err.println("Error in URLReader while reading: " +
e.getMessage());
  }finally{
   try{
    br.close();
    isr.close();
    bis.close();
    is.close();
   }catch (Exception e){
    System.err.println ("Error in URLReader when closing up: " +
e.getMessage());
   }
   is = null;
   bis = null;
   isr = null;
   br = null;
   s = null;
  }
  return sb.toString();
 }
Technical Details
Message-ID: <4240a17f$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!pd7cy2so!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,6574813dc04e4e07,start
X-Google-Attributes: gidf74b3,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Scott Powell" <spowell@rpsweb.com>
From: "Scott Powell" <spowell@rpsweb.com>
Newsgroups: borland.public.jbuilder.java.language
Subject: The static method readURL(String) from the type URLReader should be accessed in a static way 
Date: Tue, 22 Mar 2005 14:47:24 -0800
Lines: 58
Organization: RPS
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.224
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.224
NNTP-Posting-Host: 64.80.153.236
Message-ID: <4240a17f$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1111531903 64.80.153.236 (22 Mar 2005 14:51:43 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!pd7cy2so!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail