























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
























4
if (listeners == null) listeners.remove(listener);
FindBugs looks for a statement or branch that, if executed, guarantees a null pointer exception
Either a null pointer exception could be thrown, or the program contains a statement/branch that can’t be executed
Could look for exceptions that only occur on a path
e.g., if the condition on line 29 is true and the condition on line 38 is false, then a NPE will be thrown
but would need to worry about whether that path is feasible
Examples of null pointer bugs //com.sun.corba.se.impl.naming.cosnaming.NamingContextImpl if (name != null || name.length > 0) //com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser if (part == null | part.equals("")) // sun.awt.x11.ScrollPanePeer if (g != null) paintScrollBars(g,colors); g.dispose(); simple ones
Checking a value to see if it is null
When it can't possibly be null // java.awt.image.LoopupOp, lines 236- public final WritableRaster filter( Raster src, WritableRaster dst) { int dstLength = dst.getNumBands(); // Create a new destination Raster, // if needed if (dst == null) dst = createCompatibleDestRaster(src); Also known as a reverse null dereference error
// com.sun.rowset.CachedRowSetImpl if (type == Types.DECIMAL || type == Types.NUMERIC) ((java.math.BigDecimal)x).setScale(scale); // com.sun.xml.internal.txw2.output.XMLWriter try { ... } catch (IOException e) { new SAXException("Server side Exception:" + e); }