List Info

Thread: Prevention of NPE in Input




Prevention of NPE in Input
user name
2006-07-26 04:33:28
Devs,
I noticed a point where an NullPointerException may occur in org.red5.io.amf.Input

1. Add update member to represent a default absolute minimum value

    protected byte currentDataType = Byte.MIN_VALUE ;

2. Change the readDataType() method to always return 'something' and not cause an NPE

 ;   public byte readDataType() {
       
        if (buf==null){
            log.error("Why is buf null?";);
   ;        
            //XXX Paul: prevent an NPE here by returning the current data type
 ;           //when there is a null buffer
           
            //if we have a currentDataType then return it
   ;         if (currentDataType == Byte.MIN_VALUE) {
                log.warn("Current data type not set");
            }
            return currentDataType;
        }
       ; currentDataType = buf.get ();


   Old method body being replace

        if(buf==null){
   ;         log.error("Why is buf null?";);
        }
        currentDataType = buf.get();


Paul
--
The early bird may get the worm, but the second mouse gets the cheese.
Prevention of NPE in Input
user name
2006-07-26 08:26:52
Mondain wrote:
> Devs,
> I noticed a point where an NullPointerException may
occur in 
> org.red5.io.amf.Input
> 
> 1. Add update member to represent a default absolute
minimum value
> 
>     protected byte currentDataType = Byte.MIN_VALUE ;
> 
> 2. Change the readDataType() method to always return
'something' and not 
> cause an NPE

Hmm, shouldn't this better raise a proper exception instead
of returning
something that's not in the input buffer?

Joachim

_______________________________________________
Red5devs mailing list
Red5devsosflash.org
http://osflash.org/mailman/listinfo/red5devs_osflash.org

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )