You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Steve R Burrus <bu...@swbell.net> on 2006/11/12 23:52:12 UTC

How do I ........?

I know that this question of  mine has been asked/answered in this 
group, but I was wondering how do I go about checking for a null value? 
I feel the need to do this in a servlet file that incorporates an image 
into it.



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do I ........?

Posted by Martin Gainty <mg...@hotmail.com>.
You may want to consider using ant to automate these tasks so you are not sidetracked by environment specific maladies

M-
This e-mail communication and any attachments may contain confidential and privileged information for the use of the 
designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its 
contents
----- Original Message ----- 
From: "steve Burrus" <bu...@swbell.net>
To: "Tomcat Users List" <us...@tomcat.apache.org>; "Martin Gainty" <mg...@hotmail.com>
Sent: Monday, November 13, 2006 12:09 AM
Subject: Re: How do I ........?


> well I got it right with that one image, saw it in my web browser, after 
> taking out all of the special characters. But when I tried to do the same 
> thing with another img. I am afraid that I had an unpleasant return back to 
> the old NullPointerException!! Can you please continue to give me some help 
> w. this? Thanx.
> 
> ----- Original Message ----- 
> From: "Martin Gainty" <mg...@hotmail.com>
> To: "Tomcat Users List" <us...@tomcat.apache.org>
> Sent: Sunday, November 12, 2006 7:04 PM
> Subject: Re: How do I ........?
> 
> 
>>I dont think you can use special characters as your filename
>> so ren your image to image.jpg then re-get using
>>
>> logo = getServletContext().getResourceAsStream("image.jpg");
>>
>> M-
>> This e-mail communication and any attachments may contain confidential and 
>> privileged information for the use of the
>> designated recipients named above. If you are not the intended recipient, 
>> you are hereby notified that you have received
>> this communication in error and that any review, disclosure, 
>> dissemination, distribution or copying of it or its
>> contents
>> ----- Original Message ----- 
>> From: "Steve R Burrus" <bu...@swbell.net>
>> To: "Tomcat Users List" <us...@tomcat.apache.org>
>> Sent: Sunday, November 12, 2006 7:06 PM
>> Subject: Re: How do I ........?
>>
>>
>>> here is the entire code for the image servlet which I seem to be
>>> repeatedly getting that NullPointerException java exception. Any ideas
>>> what the problem is ? :
>>>
>>>                            package coreservlets;
>>>
>>>                             import java.io.*;
>>>                             import javax.servlet.*;
>>>                             import javax.servlet.http.*;
>>>
>>> public class Image_File extends HttpServlet {
>>>     public void doGet( HttpServletRequest rq, HttpServletResponse rp )
>>> throws
>>>                                                       ServletException,
>>> IOException {
>>>        rp.setContentType( "image/jpeg" );
>>>
>>>        ServletContext sc = getServletContext ();
>>>        InputStream in = 
>>> sc.getResourceAsStream("/Sexy_Laundry_Girl!.JPG");
>>>
>>>        int r = 0;
>>>        byte[] by = new byte[4096];
>>>
>>>        OutputStream os = rp.getOutputStream();
>>>        while( ( r = in.read(by)) != -1) {
>>>             // if (r in= null)
>>>            os.write(by, 0, r);
>>>       }
>>>       os.flush();
>>>       os.close() ;
>>>   }
>>> }
>>>
>>>
>>> Martin Gainty wrote:
>>>
>>>>you can always wrap your accesor in a simple try/catch block as in
>>>>try
>>>>{
>>>> Image logo=null;
>>>>  logo = Toolkit.getDefaultToolkit().getImage("images/splash.png");
>>>>}
>>>>catch(NullPointerException excp)
>>>>{
>>>> log.debug("NullPointerException thrown while retreiving image 
>>>> images/splash.png");
>>>> System.out.println("NullPointerException thrown while retrieving 
>>>> images/splash.png");
>>>>}
>>>>
>>>>Anyone else?
>>>>
>>>>M-
>>>>This e-mail communication and any attachments may contain confidential 
>>>>and privileged information for the use of the
>>>>designated recipients named above. If you are not the intended recipient, 
>>>>you are hereby notified that you have received
>>>>this communication in error and that any review, disclosure, 
>>>>dissemination, distribution or copying of it or its
>>>>contents
>>>>----- Original Message ----- 
>>>>From: "Steve R Burrus" <bu...@swbell.net>
>>>>To: <us...@tomcat.apache.org>
>>>>Sent: Sunday, November 12, 2006 5:52 PM
>>>>Subject: How do I ........?
>>>>
>>>>
>>>>
>>>>
>>>>>I know that this question of  mine has been asked/answered in this
>>>>>group, but I was wondering how do I go about checking for a null value?
>>>>>I feel the need to do this in a servlet file that incorporates an image
>>>>>into it.
>>>>>
>>>>>
>>>>>
>>>>>---------------------------------------------------------------------
>>>>>To start a new topic, e-mail: users@tomcat.apache.org
>>>>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>>For additional commands, e-mail: users-help@tomcat.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>> 
> 
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
>

Re: How do I ........?

Posted by steve Burrus <bu...@swbell.net>.
well I got it right with that one image, saw it in my web browser, after 
taking out all of the special characters. But when I tried to do the same 
thing with another img. I am afraid that I had an unpleasant return back to 
the old NullPointerException!! Can you please continue to give me some help 
w. this? Thanx.

----- Original Message ----- 
From: "Martin Gainty" <mg...@hotmail.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Sunday, November 12, 2006 7:04 PM
Subject: Re: How do I ........?


>I dont think you can use special characters as your filename
> so ren your image to image.jpg then re-get using
>
> logo = getServletContext().getResourceAsStream("image.jpg");
>
> M-
> This e-mail communication and any attachments may contain confidential and 
> privileged information for the use of the
> designated recipients named above. If you are not the intended recipient, 
> you are hereby notified that you have received
> this communication in error and that any review, disclosure, 
> dissemination, distribution or copying of it or its
> contents
> ----- Original Message ----- 
> From: "Steve R Burrus" <bu...@swbell.net>
> To: "Tomcat Users List" <us...@tomcat.apache.org>
> Sent: Sunday, November 12, 2006 7:06 PM
> Subject: Re: How do I ........?
>
>
>> here is the entire code for the image servlet which I seem to be
>> repeatedly getting that NullPointerException java exception. Any ideas
>> what the problem is ? :
>>
>>                            package coreservlets;
>>
>>                             import java.io.*;
>>                             import javax.servlet.*;
>>                             import javax.servlet.http.*;
>>
>> public class Image_File extends HttpServlet {
>>     public void doGet( HttpServletRequest rq, HttpServletResponse rp )
>> throws
>>                                                       ServletException,
>> IOException {
>>        rp.setContentType( "image/jpeg" );
>>
>>        ServletContext sc = getServletContext ();
>>        InputStream in = 
>> sc.getResourceAsStream("/Sexy_Laundry_Girl!.JPG");
>>
>>        int r = 0;
>>        byte[] by = new byte[4096];
>>
>>        OutputStream os = rp.getOutputStream();
>>        while( ( r = in.read(by)) != -1) {
>>             // if (r in= null)
>>            os.write(by, 0, r);
>>       }
>>       os.flush();
>>       os.close() ;
>>   }
>> }
>>
>>
>> Martin Gainty wrote:
>>
>>>you can always wrap your accesor in a simple try/catch block as in
>>>try
>>>{
>>> Image logo=null;
>>>  logo = Toolkit.getDefaultToolkit().getImage("images/splash.png");
>>>}
>>>catch(NullPointerException excp)
>>>{
>>> log.debug("NullPointerException thrown while retreiving image 
>>> images/splash.png");
>>> System.out.println("NullPointerException thrown while retrieving 
>>> images/splash.png");
>>>}
>>>
>>>Anyone else?
>>>
>>>M-
>>>This e-mail communication and any attachments may contain confidential 
>>>and privileged information for the use of the
>>>designated recipients named above. If you are not the intended recipient, 
>>>you are hereby notified that you have received
>>>this communication in error and that any review, disclosure, 
>>>dissemination, distribution or copying of it or its
>>>contents
>>>----- Original Message ----- 
>>>From: "Steve R Burrus" <bu...@swbell.net>
>>>To: <us...@tomcat.apache.org>
>>>Sent: Sunday, November 12, 2006 5:52 PM
>>>Subject: How do I ........?
>>>
>>>
>>>
>>>
>>>>I know that this question of  mine has been asked/answered in this
>>>>group, but I was wondering how do I go about checking for a null value?
>>>>I feel the need to do this in a servlet file that incorporates an image
>>>>into it.
>>>>
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To start a new topic, e-mail: users@tomcat.apache.org
>>>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>For additional commands, e-mail: users-help@tomcat.apache.org
>>>>
>>>>
>>>>
>>>>
>>>
>> 



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do I ........?

Posted by Martin Gainty <mg...@hotmail.com>.
I dont think you can use special characters as your filename
so ren your image to image.jpg then re-get using

 logo = getServletContext().getResourceAsStream("image.jpg");

M-
This e-mail communication and any attachments may contain confidential and privileged information for the use of the 
designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its 
contents
----- Original Message ----- 
From: "Steve R Burrus" <bu...@swbell.net>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Sunday, November 12, 2006 7:06 PM
Subject: Re: How do I ........?


> here is the entire code for the image servlet which I seem to be 
> repeatedly getting that NullPointerException java exception. Any ideas 
> what the problem is ? :
> 
>                            package coreservlets;
> 
>                             import java.io.*;
>                             import javax.servlet.*;
>                             import javax.servlet.http.*;
> 
> public class Image_File extends HttpServlet {
>     public void doGet( HttpServletRequest rq, HttpServletResponse rp ) 
> throws
>                                                       ServletException, 
> IOException {
>        rp.setContentType( "image/jpeg" );
> 
>        ServletContext sc = getServletContext ();
>        InputStream in = sc.getResourceAsStream("/Sexy_Laundry_Girl!.JPG");
> 
>        int r = 0;
>        byte[] by = new byte[4096];
> 
>        OutputStream os = rp.getOutputStream();
>        while( ( r = in.read(by)) != -1) {
>             // if (r in= null)
>            os.write(by, 0, r);
>       }
>       os.flush();
>       os.close() ;
>   }
> }
> 
> 
> Martin Gainty wrote:
> 
>>you can always wrap your accesor in a simple try/catch block as in
>>try
>>{
>> Image logo=null;
>>  logo = Toolkit.getDefaultToolkit().getImage("images/splash.png");
>>}
>>catch(NullPointerException excp)
>>{
>> log.debug("NullPointerException thrown while retreiving image images/splash.png");
>> System.out.println("NullPointerException thrown while retrieving images/splash.png");
>>}
>>
>>Anyone else?
>>
>>M-
>>This e-mail communication and any attachments may contain confidential and privileged information for the use of the 
>>designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
>>this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its 
>>contents
>>----- Original Message ----- 
>>From: "Steve R Burrus" <bu...@swbell.net>
>>To: <us...@tomcat.apache.org>
>>Sent: Sunday, November 12, 2006 5:52 PM
>>Subject: How do I ........?
>>
>>
>>  
>>
>>>I know that this question of  mine has been asked/answered in this 
>>>group, but I was wondering how do I go about checking for a null value? 
>>>I feel the need to do this in a servlet file that incorporates an image 
>>>into it.
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To start a new topic, e-mail: users@tomcat.apache.org
>>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>    
>>>
>>>
>>
>

RE: [SFnOT]Re: How do I ........?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net] 
> Subject: [SFnOT]Re: How do I ........?
> 
> I weep for you, Martin.

Actually, I'd weep for anyone that hired him.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


[SFnOT]Re: How do I ........?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin,

Wow. More drivel. SS and DS? I see you're familiar with x86 assembly. I
weep for you, Martin.

Martin Gainty wrote:
> This is one of those SS!=DS discussions which means that variables
> placed/alloc'ed on the stack are NOT the same as variables alloc'ed
> from heap so when using a variable which is  alloced  on the stack
> AND initialised to some known value (null) feel free to test that
> pre-allocated stack variable as with if(stack_variable == null)

Where to begin....

In Java, all reference types (which includes all object types as well as
arrays) are allocated on the heap. All. All all all.

All /references/ (those are the names that you give to them in your
functions, like "foo" are allocated on the stack. All. All all all.

Non reference types (also called primitives) may never have a null value
in Java. Never never never.

If a reference is equal to null, and you try to dereference it, you will
get a NPE.

The solution is simple: do not dereference null references. Duh!

> If you dont know how this variable is alloc'ed or you know that the
> variable is alloc'ed from heap use try / catch(NullPointerException
> npe)

The variable is always a reference variable because we're talking about
nulls. Reference types always go on the heap, therefore you are getting
heap allocation. The reference itself is always local, on the stack.

Catching NPE is just sloppy coding.

> to do otherwise you're risking your webapp causing 'an unhandled
> exception' when referencing a unalloc'ed variable..

There is no such operation as "referencing" a variable. Simply
mentioning a variable name in an expression (even if it is null) is not
enough to throw an NPE. You have to dereference it.

The definition of "dereference" is an exercise left to the reader, if
his eyes haven't bled so much he can no longer see, which is about where
I am.

Let's kill this thread. Dead thread dead.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFW67q9CaO5/Lv0PARAi1tAJ4xqphcj0AdwpjFV8lj/RVnXpphhACfes+x
alSUKSwZFLIiMOL/9sDNNZU=
=7ZZy
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT] How do I ........?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chuck,

Caldarale, Charles R wrote:
> [...] their allocation is up to the particular JVM
> implementation and need not be materialized in memory at all.

This is a good point that I didn't mention.

The description I have given indicates how Java will behave. For
instance, all objects "behave" as if allocated on the heap, and all
primitives (of which a reference is one... sort of) act as if they were
allocated on the stack.

JITs can basically do anything they want as long as they don't break
these rules.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFW7Vu9CaO5/Lv0PARAv+0AJ0cLDn7a0PhVjlbrW6c0G1JsLxv6gCdGtOF
eh5DQcihbfo390b1lJgQgmQ=
=fhZe
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: [OT] How do I ........?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Martin Gainty [mailto:mgainty@hotmail.com] 
> Subject: Re: How do I ........?
> 
> This is one of those SS!=DS discussions which means that 
> variables placed/alloc'ed on the stack are NOT the same as 
> variables alloc'ed from heap
> so 
> when using a variable which is  alloced  on the stack AND 
> initialised to some known value (null) 
> feel free to test that pre-allocated stack variable as with 
> if(stack_variable == null)
> 
> If you dont know how this variable is alloc'ed or you know 
> that the variable is alloc'ed from heap use try / 
> catch(NullPointerException npe)
> 
> to do otherwise you're risking your webapp causing 'an 
> unhandled exception' when referencing a unalloc'ed variable..

A continuing display of your ignorance and irrelevance.

Sounds like you're confusing the issue with variable and field
initialization.  Variables in Java are always thread-local and within
the scope of a method; their allocation is up to the particular JVM
implementation and need not be materialized in memory at all.  They also
do not have any pre-defined initial values in lieu of an explicit
initialization expression.

Fields are associated with an object instance or class (if static); most
JVMs do allocate objects from a heap, but again there's no spec
requirement to do so.  Static fields are also usually allocated from a
heap, but not necessarily the same one as instances.  By definition,
fields have an initial value of zero, null, or false (depending on
type), if not specified by an initialization expression.

None of this has any bearing on whether or not it's valid to use a var
== null expression, which, of course, is always an acceptable thing to
do.  The fact that you can't seem to do it speaks only to your
programming skills, not anything in the Java language.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do I ........?

Posted by Martin Gainty <mg...@hotmail.com>.
This is one of those SS!=DS discussions which means that variables placed/alloc'ed on the stack are NOT the same as variables alloc'ed from heap
so 
when using a variable which is  alloced  on the stack AND initialised to some known value (null) 
feel free to test that pre-allocated stack variable as with if(stack_variable == null)

If you dont know how this variable is alloc'ed or you know that the variable is alloc'ed from heap use try / catch(NullPointerException npe)

to do otherwise you're risking your webapp causing 'an unhandled exception' when referencing a unalloc'ed variable..

GL,
M-
This e-mail communication and any attachments may contain confidential and privileged information for the use of the 
designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its 
contents
----- Original Message ----- 
From: "Steve R Burrus" <bu...@swbell.net>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Wednesday, November 15, 2006 2:35 PM
Subject: Re: How do I ........?


> just a tiny correction for you Chris, and that is that the code ought to 
> be "if(in = = null)" not as u had it "if(null = = in)". Am I right or not?
> 
> Christopher Schultz wrote:
> 
>>-----BEGIN PGP SIGNED MESSAGE-----
>>Hash: SHA1
>>
>>Steve,
>>
>>Steve R Burrus wrote:
>>  
>>
>>>hi chris this is steve Burrus and the line of code in question is the
>>>while loop : "while( ( r = in.read(by)) != -1) {" the server error for a
>>>long time has always pointed to that line of code creating the NPE.
>>>    
>>>
>>
>>Yup, that's the first time you use the InputStream after attempting to
>>load your file. It's pretty simple to check for null: just use the code
>>I suggested in my last message:
>>
>>  
>>
>>>>Correct me if I'm wrong, but this generally checks for null:
>>>>
>>>>if(null == in)
>>>>  // handle the null condition
>>>>      
>>>>
>>
>>Now, it's up to you what you want to do in the event of a NULL image.
>>You could either return a "404 Not Found" error status, or return a
>>known good image that actually says "ERROR" on it.
>>
>>- -chris
>>
>>-----BEGIN PGP SIGNATURE-----
>>Version: GnuPG v1.4.5 (MingW32)
>>Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>>
>>iD8DBQFFWM4Y9CaO5/Lv0PARArEgAKC8p+909qemHgpbGFmO5Fooh8AWcACeLF29
>>ajQlvN1B+YLbdmoKa+TFoyM=
>>=G5GE
>>-----END PGP SIGNATURE-----
>>
>>---------------------------------------------------------------------
>>To start a new topic, e-mail: users@tomcat.apache.org
>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
>>  
>>
>

RE: [OT[ How do I ........?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Leon Rosenberg [mailto:rosenberg.leon@googlemail.com] 
> Subject: Re: [OT[ How do I ........?
> 
> as long as you don't parenthesise everything just for the fun of it,
> like in tomcats code, you shouldn't have fear, warrior.
> 
>   public String getAuthType() {
>         return (this.authType);
>   }
> 
> being off topic, does someone know the source of this evil? :-)

It's functional (pun intended).

One of my pet peeves as well.  Perhaps the originator thought return
really was a function call?  Or maybe an out of work Lisp programmer?

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT[ How do I ........?

Posted by Leon Rosenberg <ro...@googlemail.com>.
On 11/15/06, Christopher Schultz <ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Chuck,
>
> Caldarale, Charles R wrote:
> >> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> >> Subject: Re: [OT[ How do I ........?
> >>
> >>> Belt and suspenders?
> >> It's just a habit, okay!?   :P
> >
> > Not complaining; I think it's a clever and wholly appropriate thing to
> > do.
>
> Oh, that was me feigning horror. Everyone looks at me funny when I put
> the terms "the wrong way". It doesn't bother me. It makes me look
> war-torn or something. Or maybe just like an idiot who can't read his
> own code ;)

as long as you don't parenthesise everything just for the fun of it,
like in tomcats code, you shouldn't have fear, warrior.

  public String getAuthType() {
        return (this.authType);
  }

being off topic, does someone know the source of this evil? :-)

regards
Leon


>
> - -chris
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT[ How do I ........?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chuck,

Caldarale, Charles R wrote:
>> From: Christopher Schultz [mailto:chris@christopherschultz.net] 
>> Subject: Re: [OT[ How do I ........?
>>
>>> Belt and suspenders?
>> It's just a habit, okay!?   :P
> 
> Not complaining; I think it's a clever and wholly appropriate thing to
> do.

Oh, that was me feigning horror. Everyone looks at me funny when I put
the terms "the wrong way". It doesn't bother me. It makes me look
war-torn or something. Or maybe just like an idiot who can't read his
own code ;)

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFW4dP9CaO5/Lv0PARAp82AKDA6Dyt44KRyFGv/o64///B7/23vACgoO3x
zsS1Muo1p4vZ/tCP7dEleyc=
=zbFu
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: [OT[ How do I ........?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net] 
> Subject: Re: [OT[ How do I ........?
> 
> > Belt and suspenders?
> 
> It's just a habit, okay!?   :P

Not complaining; I think it's a clever and wholly appropriate thing to
do.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT[ How do I ........?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chuck,

Caldarale, Charles R wrote:
>> From: Christopher Schultz [mailto:chris@christopherschultz.net] 
>> Subject: Re: How do I ........?
>>
>> Since you get bitten in C by missing an equals (it's quite easily to
>> miss it visually), I got into the habit of putting the null first.
> 
> Belt and suspenders?

It's just a habit, okay!?   :P

- -chris

> 
>> Why the heck are we discussing things like this on a mailing 
>> list for an app server!?
> 
> Programming class 0.9 ...
> 
>  - Chuck
> 
> 
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFW4Fu9CaO5/Lv0PARAuZAAJoC2nJCKQZlyOnD4FQpU4/x/np3WgCfXveo
15DilI+f87JJUeb1EGBPdUo=
=tySa
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: [OT[ How do I ........?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net] 
> Subject: Re: How do I ........?
> 
> Since you get bitten in C by missing an equals (it's quite easily to
> miss it visually), I got into the habit of putting the null first.

Belt and suspenders?

> Why the heck are we discussing things like this on a mailing 
> list for an app server!?

Programming class 0.9 ...

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do I ........?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

All,

Caldarale, Charles R wrote:
>> From: Steve R Burrus [mailto:burrus1@swbell.net] 
>> just a tiny correction for you Chris, and that is that the 
>> code ought to 
>> be "if(in = = null)" not as u had it "if(null = = in)". Am I 
>> right or not?
> 
> No, you're not.  The order of operands makes no difference for an
> equality test.  (And don't put spaces in the middle of operators -
> that's not what Chris wrote.)

My use of the 'null' argument first in equality checking comes from my
use of the C programming language. In C, this is a valid statement and
generally does not do what you want:

if(in = null)

In Java, this is a syntax error. (Note the single = sign, indicating
assignment, instead of a double == indicating comparison).

Since you get bitten in C by missing an equals (it's quite easily to
miss it visually), I got into the habit of putting the null first.

As Chuck points out, it's exactly the same thing. Oh, and you can't put
spaces between the equals signs, or the compiler won't recognize it as
the equality operator. The equality operator is "==". It is /not/ two
equals signs, contrary to popular belief. Spaces are simply not allowed.

Why the heck are we discussing things like this on a mailing list for an
app server!?

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFW34F9CaO5/Lv0PARAl9TAKCrxUD0kgy+8CqsQulbl5TRNzuC2gCgjjEa
Gi0vYdQJ4gp3B5uE+YyzFJE=
=2zBd
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: How do I ........?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Steve R Burrus [mailto:burrus1@swbell.net] 
> Subject: Re: How do I ........?
> 
> just a tiny correction for you Chris, and that is that the 
> code ought to 
> be "if(in = = null)" not as u had it "if(null = = in)". Am I 
> right or not?

No, you're not.  The order of operands makes no difference for an
equality test.  (And don't put spaces in the middle of operators -
that's not what Chris wrote.)

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do I ........?

Posted by Steve R Burrus <bu...@swbell.net>.
just a tiny correction for you Chris, and that is that the code ought to 
be "if(in = = null)" not as u had it "if(null = = in)". Am I right or not?

Christopher Schultz wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Steve,
>
>Steve R Burrus wrote:
>  
>
>>hi chris this is steve Burrus and the line of code in question is the
>>while loop : "while( ( r = in.read(by)) != -1) {" the server error for a
>>long time has always pointed to that line of code creating the NPE.
>>    
>>
>
>Yup, that's the first time you use the InputStream after attempting to
>load your file. It's pretty simple to check for null: just use the code
>I suggested in my last message:
>
>  
>
>>>Correct me if I'm wrong, but this generally checks for null:
>>>
>>>if(null == in)
>>>  // handle the null condition
>>>      
>>>
>
>Now, it's up to you what you want to do in the event of a NULL image.
>You could either return a "404 Not Found" error status, or return a
>known good image that actually says "ERROR" on it.
>
>- -chris
>
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.4.5 (MingW32)
>Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
>iD8DBQFFWM4Y9CaO5/Lv0PARArEgAKC8p+909qemHgpbGFmO5Fooh8AWcACeLF29
>ajQlvN1B+YLbdmoKa+TFoyM=
>=G5GE
>-----END PGP SIGNATURE-----
>
>---------------------------------------------------------------------
>To start a new topic, e-mail: users@tomcat.apache.org
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
>  
>

Re: How do I ........?

Posted by Markus Schönhaber <ma...@schoenhaber.de>.
Martin Gainty wrote:
> Well bs chuck and laughing dave
>
> I ran your exact example / deleted FunkyImage.jpg and got this on screen
>
> java.lang.NullPointerException
> 	coreservlets.ImageFile.doGet(ImageFile.java:34)
> 	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
> 	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>
> **********But wait a minute Im NOT supposed to get NullPointerException
> !!!!!***********
>
> public class ImageFile extends HttpServlet
> {
>  public void doGet( HttpServletRequest rq, HttpServletResponse rp ) throws 
> ServletException, IOException // public static void main(String[] args)
>  {
> //     javax.servlet.http.HttpServletResponse rp;
> //     javax.servlet.http.HttpServletRequest rq;
>      ServletContext sc;
>
>         rp.setContentType( "image/jpeg" );
>
>         sc = getServletContext ();
>         InputStream in = sc.getResourceAsStream("FunkyImage.JPG");
>
>         int r = 0;
>         byte[] by = new byte[4096];
>
>         OutputStream os = rp.getOutputStream();
>
>             if (in==null) System.out.println("This is when in == null");
>
>         while( ( r = in.read(by)) != -1)
>         {
>             if (in==null) System.out.println("This is when in == null");
>            os.write(by, 0, r);
>         }
>         os.flush();
>         os.close() ;
>    } //DoGet
>  } //ImageFile
>
> How is it that (in==null) didnt evaluate true ?
>
> Comments?

Aren't you the one who recently offered a programming duel?

Regards
  mks

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do I ........?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David,

>     * Throwing |null| as if it were a |Throwable| value.

Wow, I never knew that one. You learn something new every day.

I guess I was always careful not to "throw null" ;)

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFWObX9CaO5/Lv0PARAt7HAJ4mD9afqSRJYIBFXaoB+6kD0w0q9gCgmQ6Q
ogXGN41g55NeiDBjWAeW5FA=
=YDtH
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: How do I ........?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Martin Gainty [mailto:mgainty@hotmail.com] 
> Subject: Re: How do I ........?
> 
> **********But wait a minute Im NOT supposed to get 
> NullPointerException !!!!!***********

Of course you are - you continued to try to use a method of the null
object even after determining that it was null:

>             if (in==null) System.out.println("This is when in ==
null");
>         while( ( r = in.read(by)) != -1)
>
> How is it that (in==null) didnt evaluate true ?

It did, of course.  Your previous output was thrown away when the
exception occurred and replaced by the error page.

To make it simpler, here's your original code inside a simple class.
Try running it.

class Dummy {
  public static void main(String[] args) {
    Object in = null;
    try {
      if (in == null) System.out.println("This statement will never be
executed as NullPointerException will be thrown");
    } catch(NullPointerException npe) {
      System.out.println("variable in has thrown NullPointerException so
something about that here");
    }
  }
}

Then take a programming class.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do I ........?

Posted by Martin Gainty <mg...@hotmail.com>.
Well bs chuck and laughing dave

I ran your exact example / deleted FunkyImage.jpg and got this on screen

java.lang.NullPointerException
	coreservlets.ImageFile.doGet(ImageFile.java:34)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

**********But wait a minute Im NOT supposed to get NullPointerException !!!!!***********

public class ImageFile extends HttpServlet
{
 public void doGet( HttpServletRequest rq, HttpServletResponse rp ) throws  ServletException, IOException
// public static void main(String[] args)
 {
//     javax.servlet.http.HttpServletResponse rp;
//     javax.servlet.http.HttpServletRequest rq;
     ServletContext sc;

        rp.setContentType( "image/jpeg" );

        sc = getServletContext ();
        InputStream in = sc.getResourceAsStream("FunkyImage.JPG");

        int r = 0;
        byte[] by = new byte[4096];

        OutputStream os = rp.getOutputStream();

            if (in==null) System.out.println("This is when in == null");

        while( ( r = in.read(by)) != -1)
        {
            if (in==null) System.out.println("This is when in == null");
           os.write(by, 0, r);
        }
        os.flush();
        os.close() ;
   } //DoGet
 } //ImageFile

How is it that (in==null) didnt evaluate true ?

Comments?
M-
This e-mail communication and any attachments may contain confidential and privileged information for the use of the 
designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its 
contents
----- Original Message ----- 
From: "david.delbecq" <da...@oma.be>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Monday, November 13, 2006 4:03 PM
Subject: Re: How do I ........?


> o.O
> 
> .............
> .............
> (not laughing, not laughing, not laughing)
> 
> this is going to be my funniest evening in the week, and yet it still
> monday!
> 
> 
> Martin Gainty a écrit :
>> the instant you execute code where a variable is NULL you will  throw
> NullPointerException
> 
> Change your books! Here are the conditions in which
> NullPointerExceptions can be thrown (can be found in sun's javadocs)
> 
> Thrown when an application attempts to use |null| in a case where an
> object is required. These include:
> 
>    * Calling the instance method of a |null| object.
>    * Accessing or modifying the field of a |null| object.
>    * Taking the length of |null| as if it were an array.
>    * Accessing or modifying the slots of |null| as if it were an array.
>    * Throwing |null| as if it were a |Throwable| value.
> 
> Applications should throw instances of this class to indicate other
> illegal uses of the |null| object.
> 
> 
> (notice the use of the term *required*)
> 
>> if you want robust code you are better off wrapping in try catch block
> as in
>> try
>> {
>>  if( in == null) System.out.println("This statement will never be
> executed as NullPointerException will be thrown");
>> }
>> catch(NullPointerException npe)
>> {
>>   System.out.println("variable in has thrown NullPointerException so
> something about that here");
>> }
> 
> Did you actually *tried* that code?
> 
>>
>> This e-mail communication and any attachments may contain confidential
> and privileged information for the use of the
>> designated recipients named above. If you are not the intended
> recipient, you are hereby notified that you have received
>> this communication in error and that any review, disclosure,
> dissemination, distribution or copying of it or its
>> contents
>> ----- Original Message -----
>> From: "Christopher Schultz" <ch...@christopherschultz.net>
>> To: "Tomcat Users List" <us...@tomcat.apache.org>
>> Sent: Monday, November 13, 2006 2:57 PM
>> Subject: Re: How do I ........?
>>
>>
>> Steve,
>>
>> Steve R Burrus wrote:
>> >>> hi chris this is steve Burrus and the line of code in question is the
>> >>> while loop : "while( ( r = in.read(by)) != -1) {" the server error
>> for a
>> >>> long time has always pointed to that line of code creating the NPE.
>> Yup, that's the first time you use the InputStream after attempting to
>> load your file. It's pretty simple to check for null: just use the code
>> I suggested in my last message:
>>
>> >>>> Correct me if I'm wrong, but this generally checks for null:
>> >>>>
>> >>>> if(null == in)
>> >>>>   // handle the null condition
>> Now, it's up to you what you want to do in the event of a NULL image.
>> You could either return a "404 Not Found" error status, or return a
>> known good image that actually says "ERROR" on it.
>>
>> -chris
>>
>>>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>
> 
> Mouhahahahaha. (sorry, couldn't hold it)
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
>

Re: How do I ........?

Posted by "david.delbecq" <da...@oma.be>.
o.O

.............
.............
(not laughing, not laughing, not laughing)

this is going to be my funniest evening in the week, and yet it still
monday!


Martin Gainty a écrit :
> the instant you execute code where a variable is NULL you will  throw
NullPointerException

Change your books! Here are the conditions in which
NullPointerExceptions can be thrown (can be found in sun's javadocs)

Thrown when an application attempts to use |null| in a case where an
object is required. These include:

    * Calling the instance method of a |null| object.
    * Accessing or modifying the field of a |null| object.
    * Taking the length of |null| as if it were an array.
    * Accessing or modifying the slots of |null| as if it were an array.
    * Throwing |null| as if it were a |Throwable| value.

Applications should throw instances of this class to indicate other
illegal uses of the |null| object.


(notice the use of the term *required*)

> if you want robust code you are better off wrapping in try catch block
as in
> try
> {
>  if( in == null) System.out.println("This statement will never be
executed as NullPointerException will be thrown");
> }
> catch(NullPointerException npe)
> {
>   System.out.println("variable in has thrown NullPointerException so
something about that here");
> }

Did you actually *tried* that code?

>
> This e-mail communication and any attachments may contain confidential
and privileged information for the use of the
> designated recipients named above. If you are not the intended
recipient, you are hereby notified that you have received
> this communication in error and that any review, disclosure,
dissemination, distribution or copying of it or its
> contents
> ----- Original Message -----
> From: "Christopher Schultz" <ch...@christopherschultz.net>
> To: "Tomcat Users List" <us...@tomcat.apache.org>
> Sent: Monday, November 13, 2006 2:57 PM
> Subject: Re: How do I ........?
>
>
> Steve,
>
> Steve R Burrus wrote:
> >>> hi chris this is steve Burrus and the line of code in question is the
> >>> while loop : "while( ( r = in.read(by)) != -1) {" the server error
> for a
> >>> long time has always pointed to that line of code creating the NPE.
> Yup, that's the first time you use the InputStream after attempting to
> load your file. It's pretty simple to check for null: just use the code
> I suggested in my last message:
>
> >>>> Correct me if I'm wrong, but this generally checks for null:
> >>>>
> >>>> if(null == in)
> >>>>   // handle the null condition
> Now, it's up to you what you want to do in the event of a NULL image.
> You could either return a "404 Not Found" error status, or return a
> known good image that actually says "ERROR" on it.
>
> -chris
>
>>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>

Mouhahahahaha. (sorry, couldn't hold it)


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do I ........?

Posted by David Smith <dn...@cornell.edu>.
Sorry Martin -- won't work the way you did it.  Testing for null will
not throw an NPE.  That's how we avoid an NPE all together.

However if you attempt to access a method on a null object reference, it
will throw an NPE.  Example:

try {
  javax.sql.DataSource dbds = null ;
  dbds.getConnection() ; // This will definitely throw an NPE
} catch ( java.lang.NullPointerException npe ) {
  // Do something else because we couldn't get a connection
}

Welcome to java programming 101.

Additionally some methods in various APIs will throw a NPE if you
provide a null value on a parameter.

--David

Martin Gainty wrote:

>the instant you execute code where a variable is NULL you will throw
NullPointerException
>if you want robust code you are better off wrapping in try catch block
as in
>try
>{
> if( in == null) System.out.println("This statement will never be
executed as NullPointerException will be thrown");
>}
>catch(NullPointerException npe)
>{
> System.out.println("variable in has thrown NullPointerException so
something about that here");
>}
>
>This e-mail communication and any attachments may contain confidential
and privileged information for the use of the
>designated recipients named above. If you are not the intended
recipient, you are hereby notified that you have received
>this communication in error and that any review, disclosure,
dissemination, distribution or copying of it or its
>contents
>----- Original Message -----
>From: "Christopher Schultz" <ch...@christopherschultz.net>
>To: "Tomcat Users List" <us...@tomcat.apache.org>
>Sent: Monday, November 13, 2006 2:57 PM
>Subject: Re: How do I ........?
>
>

> Steve,
>
> Steve R Burrus wrote:
>
> >hi chris this is steve Burrus and the line of code in question is the
> >while loop : "while( ( r = in.read(by)) != -1) {" the server error for a
> >long time has always pointed to that line of code creating the NPE.
>
> Yup, that's the first time you use the InputStream after attempting to
> load your file. It's pretty simple to check for null: just use the code
> I suggested in my last message:
>
> >>Correct me if I'm wrong, but this generally checks for null:
>
> >>if(null == in)
> >>  // handle the null condition
>
> Now, it's up to you what you want to do in the event of a NULL image.
> You could either return a "404 Not Found" error status, or return a
> known good image that actually says "ERROR" on it.
>
> -chris
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do I ........?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin,

The following example is patently false. Do not follow its example:

Martin Gainty wrote:
> the instant you execute code where a variable is NULL you will throw 
> NullPointerException if you want robust code you are better off
> wrapping in try catch block as in
>
> try
> {
>  if( in == null)
>         System.out.println("This statement will never be executed ")
>                          + "as NullPointerException will be thrown");
> }
> catch(NullPointerException npe)
> {
>   System.out.println("variable in has thrown NullPointerException "
>                    + "so something about that here");
> }

Referencing a NULL reference is not a problem. /De/-referencing a null
reference will give you an NPE. For example:

Integer i = null;

System.out.println(i);             // Works
System.out.println(i.intValue());  // Throws NPE: i is null

Catching NullPointerException is a sign that the developer is too lazy
to check for NPEs pro-actively, and is the hallmark of poorly written code.

Do yourself a favor and check for things that are likely to be null
before you get an NPE. It will execute a whole lot faster, too ;)

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFWOZw9CaO5/Lv0PARAslcAJwJzq6DZnfj3wrSdXreUVOE8H9dsACfU/Ev
15/zmKHf2u/bOAundatCcXM=
=h85f
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: How do I ........?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Martin Gainty [mailto:mgainty@hotmail.com] 
> Subject: Re: How do I ........?
> 
> the instant you execute code where a variable is NULL you 
> will  throw NullPointerException

Absolute bullshit.

> try
> {
>  if( in == null) System.out.println("This statement will 
> never be executed as NullPointerException will be thrown");
> }
> catch(NullPointerException npe)
> {
>   System.out.println("variable in has thrown 
> NullPointerException so something about that here");
> }

Martin, did you actually try running your example?  What's your
explanation for the "never be execute" statement being printed out?

Please stop polluting the mailing list with erroneous and irrelevant
information.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do I ........?

Posted by Martin Gainty <mg...@hotmail.com>.
the instant you execute code where a variable is NULL you will  throw NullPointerException
if you want robust code you are better off wrapping in try catch block as in 
try
{
 if( in == null) System.out.println("This statement will never be executed as NullPointerException will be thrown");
}
catch(NullPointerException npe)
{
  System.out.println("variable in has thrown NullPointerException so something about that here");
}

This e-mail communication and any attachments may contain confidential and privileged information for the use of the 
designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its 
contents
----- Original Message ----- 
From: "Christopher Schultz" <ch...@christopherschultz.net>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Monday, November 13, 2006 2:57 PM
Subject: Re: How do I ........?


> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Steve,
> 
> Steve R Burrus wrote:
>> hi chris this is steve Burrus and the line of code in question is the
>> while loop : "while( ( r = in.read(by)) != -1) {" the server error for a
>> long time has always pointed to that line of code creating the NPE.
> 
> Yup, that's the first time you use the InputStream after attempting to
> load your file. It's pretty simple to check for null: just use the code
> I suggested in my last message:
> 
>>> Correct me if I'm wrong, but this generally checks for null:
>>> 
>>> if(null == in)
>>>   // handle the null condition
> 
> Now, it's up to you what you want to do in the event of a NULL image.
> You could either return a "404 Not Found" error status, or return a
> known good image that actually says "ERROR" on it.
> 
> - -chris
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.5 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iD8DBQFFWM4Y9CaO5/Lv0PARArEgAKC8p+909qemHgpbGFmO5Fooh8AWcACeLF29
> ajQlvN1B+YLbdmoKa+TFoyM=
> =G5GE
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
>

Re: How do I ........?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Steve,

Steve R Burrus wrote:
> hi chris this is steve Burrus and the line of code in question is the
> while loop : "while( ( r = in.read(by)) != -1) {" the server error for a
> long time has always pointed to that line of code creating the NPE.

Yup, that's the first time you use the InputStream after attempting to
load your file. It's pretty simple to check for null: just use the code
I suggested in my last message:

>> Correct me if I'm wrong, but this generally checks for null:
>> 
>> if(null == in)
>>   // handle the null condition

Now, it's up to you what you want to do in the event of a NULL image.
You could either return a "404 Not Found" error status, or return a
known good image that actually says "ERROR" on it.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFWM4Y9CaO5/Lv0PARArEgAKC8p+909qemHgpbGFmO5Fooh8AWcACeLF29
ajQlvN1B+YLbdmoKa+TFoyM=
=G5GE
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do I ........?

Posted by Steve R Burrus <bu...@swbell.net>.
hi chris this is steve Burrus and the line of code in question is the 
while loop : "while( ( r = in.read(by)) != -1) {" the server error for a 
long time has always pointed to that line of code creating the NPE.

Christopher Schultz wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Steve,
>
>Steve R Burrus wrote:
>  
>
>>here is the entire code for the image servlet which I seem to be
>>repeatedly getting that NullPointerException java exception. Any ideas
>>what the problem is ? :
>>    
>>
>
>What line of code does the NPE show? Please give us the line of code and
>not just the line number.
>
>I'm guessing that your JPG file is not being found, so
>sc.getResourceAsStream is returning null.
>
>Correct me if I'm wrong, but this generally checks for null:
>
>if(null == in)
>   // handle the null condition
>
>Is there something that I'm not getting??!
>
>- -chris
>
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.4.5 (MingW32)
>Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
>iD8DBQFFV/3J9CaO5/Lv0PARAvNeAKCNQ3JQLLnVBYGrz9qKLaFRA0jGvACgu+CM
>ps01WACr5sV+hluXp2s4mgU=
>=SfP5
>-----END PGP SIGNATURE-----
>
>---------------------------------------------------------------------
>To start a new topic, e-mail: users@tomcat.apache.org
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
>  
>

Re: How do I ........?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Steve,

Steve R Burrus wrote:
> here is the entire code for the image servlet which I seem to be
> repeatedly getting that NullPointerException java exception. Any ideas
> what the problem is ? :

What line of code does the NPE show? Please give us the line of code and
not just the line number.

I'm guessing that your JPG file is not being found, so
sc.getResourceAsStream is returning null.

Correct me if I'm wrong, but this generally checks for null:

if(null == in)
   // handle the null condition

Is there something that I'm not getting??!

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFV/3J9CaO5/Lv0PARAvNeAKCNQ3JQLLnVBYGrz9qKLaFRA0jGvACgu+CM
ps01WACr5sV+hluXp2s4mgU=
=SfP5
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do I ........?

Posted by Steve R Burrus <bu...@swbell.net>.
here is the entire code for the image servlet which I seem to be 
repeatedly getting that NullPointerException java exception. Any ideas 
what the problem is ? :

                            package coreservlets;

                             import java.io.*;
                             import javax.servlet.*;
                             import javax.servlet.http.*;

 public class Image_File extends HttpServlet {
     public void doGet( HttpServletRequest rq, HttpServletResponse rp ) 
throws
                                                       ServletException, 
IOException {
        rp.setContentType( "image/jpeg" );

        ServletContext sc = getServletContext ();
        InputStream in = sc.getResourceAsStream("/Sexy_Laundry_Girl!.JPG");

        int r = 0;
        byte[] by = new byte[4096];

        OutputStream os = rp.getOutputStream();
        while( ( r = in.read(by)) != -1) {
             // if (r in= null)
            os.write(by, 0, r);
       }
       os.flush();
       os.close() ;
   }
}
 

Martin Gainty wrote:

>you can always wrap your accesor in a simple try/catch block as in
>try
>{
> Image logo=null;
>  logo = Toolkit.getDefaultToolkit().getImage("images/splash.png");
>}
>catch(NullPointerException excp)
>{
> log.debug("NullPointerException thrown while retreiving image images/splash.png");
> System.out.println("NullPointerException thrown while retrieving images/splash.png");
>}
>
>Anyone else?
>
>M-
>This e-mail communication and any attachments may contain confidential and privileged information for the use of the 
>designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
>this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its 
>contents
>----- Original Message ----- 
>From: "Steve R Burrus" <bu...@swbell.net>
>To: <us...@tomcat.apache.org>
>Sent: Sunday, November 12, 2006 5:52 PM
>Subject: How do I ........?
>
>
>  
>
>>I know that this question of  mine has been asked/answered in this 
>>group, but I was wondering how do I go about checking for a null value? 
>>I feel the need to do this in a servlet file that incorporates an image 
>>into it.
>>
>>
>>
>>---------------------------------------------------------------------
>>To start a new topic, e-mail: users@tomcat.apache.org
>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>    
>>
>>
>

Re: How do I ........?

Posted by Martin Gainty <mg...@hotmail.com>.
you can always wrap your accesor in a simple try/catch block as in
try
{
 Image logo=null;
  logo = Toolkit.getDefaultToolkit().getImage("images/splash.png");
}
catch(NullPointerException excp)
{
 log.debug("NullPointerException thrown while retreiving image images/splash.png");
 System.out.println("NullPointerException thrown while retrieving images/splash.png");
}

Anyone else?

M-
This e-mail communication and any attachments may contain confidential and privileged information for the use of the 
designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its 
contents
----- Original Message ----- 
From: "Steve R Burrus" <bu...@swbell.net>
To: <us...@tomcat.apache.org>
Sent: Sunday, November 12, 2006 5:52 PM
Subject: How do I ........?


>I know that this question of  mine has been asked/answered in this 
> group, but I was wondering how do I go about checking for a null value? 
> I feel the need to do this in a servlet file that incorporates an image 
> into it.
> 
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
>