this always prints in logs in conjunction with a nullpointer…
for nullpointer it gives line in jsp servlets, it’s always this line:
if (imgsList.length == 0) {
what I do is I use java.io to count how many images are in ‘images’ dir (diff no. of images in ‘images’ dir for every page in my photosite)… is it possible that when that code runs sometimes the app hasn’t quite loaded and read that ‘images’ dir yet? is there an equiv in JSP to jQuery’s $(document).ready or something so that I’m sure app has fully loaded before it reads how many images are in ‘images’ dir? again, this error occurs intermittently, and never in my machine at home… I only find out the hard way whenever am looking @ my site in an internet cafe or something… (even at work I never get it… even if I clear cache…)
this is code I run to count images in ‘images’ dir:
FPath = “/chroot/home/…/apache-tomcat-5.5.25/webapps/” + sContext + “/” + sCurrSection + “/” + sCurrPage + “/images/”;
(I do a conditional here with getHeader(“host”) to detect whether I’m in Tomcat localhost or at my website…) then:
File dir = new File(FPath);
String imgsList;
imgsList = dir.list();
if (imgsList.length == 0) { // etc…
I have been using this code unchanged in my app for about three years… don’t get why it’s throwing this weird error now…
tested yesterday in same mach. where had gotten error the other day, it worked fine… it seems that that was the solution… I think it’s strange, but well, like you say, who knows what strange things happen on the way from the browser to the server…
You might consider changing the else if statement just to an else. There might be a way that neither one of your conditions is being meet and FPath is staying null. How, I don’t have a clue, sorry.
You are correct Log4j can be replaced with simple System.out.println() methods.
So, what it comes down to is that you most likely need to see what header information is being sent to your server so you can debug the problem. You could just do a simple System.out.println of the host value prior to assigning your FPath attribute.
We have very little control of what happens to our browsers requests once they leave our machines on the internet and intermediate servers can do strange things to our requests.
It is good that you’re not passing the whole url. So hopefully you can ignore the url length issue.
However, it still might we worth it to log all the attributes that come out of the request. Especially the getHeader(“host”). Log all the values using a tool like log4j.
What changed in the last three years. Did you just open this site up publicly?