Defective Java Code: Mistakes That Matter

2y ago
11 Views
2 Downloads
3.81 MB
50 Pages
Last View : 14d ago
Last Download : 3m ago
Upload by : Macey Ridenour
Transcription

Defective Java Code:Mistakes That MatterWilliam PughUniv. of Maryland

Defective Java CodeLearning from mistakes Iʼm the lead on FindBugs static analysis tool for defect detectionVisiting scientist at Google for the past 10 months learned a lot about coding mistakes, which onesmatter, how to catch them, how to allow acommunity to review themA little like programming puzzlers but no quiz and lots of interspersed commentary2

Static analysis Analyzes code without running it FindBugs is an open source static analysis tool, developedat the University of Maryland with a number of additional contributors Looks for bug patterns, inspired by real problems in realcodeHeld FindBugs fixit at Google May 13-14th 300 engineers provided 8,000 reviews of 4,000 issues 75 % were marked should fix or must fix more than 1,500 of the issues have already been removed3

Learned wisdom Static analysis typically finds mistakes but some mistakes donʼt matter need to find the intersection of stupid and importantThe bug that matter depend on contextStatic analysis, at best, might catch 5-10% of yoursoftware quality problems 80 % for certain specific defects but overall, not a magic bulletUsed effectively, static analysis is cheaper than othertechniques for catching the same bugs4

Null bug From Eclipse, eStateActionif (adapters null && adapters.length 0)return; Clearly a mistake First seen in Eclipse 3.2 but in practice, adapters is probably never nullIs there any impact from this? we would probably notice a null pointer exception we donʼt immediately return if length is 05

Cost when a mistake causes a fault/failure How quickly/reliability would you notice?What is the impact of the misbehavior caused by themistake?How easily could you diagnose the problem and thefix?What is the cost to deliver a fix?6

Mistakes in web services Some mistakes would manifest themselves bythrowing a runtime exception Should be logged and noticedIf it isnʼt happening now, a change might cause it tostart happening in the future But if it does, the exception will likely pinpoint themistake And pushing a fix into production is cheaper thanpushing a fix to desktop or mobile applications7

Expensive mistakes (your results may vary) Mistakes that might cost millions of dollars on thefirst day they manifestMistakes that silently cause the wrong answer to becomputed might be going wrong now, millions of times a day or might be OK now, but when it does go wrong, itwonʼt be noticed until somewhere downstream ofmistakeMistakes that are expensive or impossible to fix8

Using reference equality rather than .equalsfrom Googleʼs code (no one is perfect)class MutableDouble {private double value ;public boolean equals(final Object o) {return o instanceof MutableDouble &&((MutableDouble)o).doubleValue() doubleValue();}public Double doubleValue() {return value ;}9

Using to compare objects rather than .equals For boxed primitives, and ! are computed usingpointer equality, but , , , are computed bycomparing unboxed primitive valuesSometimes, equal boxed values are representedusing the same object but only sometimesThis can bite you on other classes (e.g., String) but boxed primitives is where people get bit10

Heisenbugs vs. deterministic bugs A Heisenbug is a mistake that only sometimesmanifests itself (e.g., a data race)Testing not likely to show error if a test fails, rerunning the test may succeedCan be very nasty to track down, impossible todebugBut how dangerous is a bug that only bites once outof 4 billion times?11

Ignoring the return value of urrentMap Long,XmitTimeStat xmit time stat .;.XmitTimeStat stat xmit time stats.get(key);if(stat null) {stat new XmitTimeStat()

Defective Java Code Learning from mistakes Iʼm the lead on FindBugs static analysis tool for defect detection Visiting scientist at Google for the past 10 months learned a lot about coding mistakes, which ones matter, how to catch them, how to allow a community to review them A little like programming puzzlers

Related Documents:

java.io Input and output java.lang Language support java.math Arbitrary-precision numbers java.net Networking java.nio "New" (memory-mapped) I/O java.rmi Remote method invocations java.security Security support java.sql Database support java.text Internationalized formatting of text and numbers java.time Dates, time, duration, time zones, etc.

Java Version Java FAQs 2. Java Version 2.1 Used Java Version This is how you find your Java version: Start the Control Panel Java General About. 2.2 Checking Java Version Check Java version on https://www.java.com/de/download/installed.jsp. 2.3 Switching on Java Console Start Control Panel Java Advanced. The following window appears:

3. _ is a software that interprets Java bytecode. a. Java virtual machine b. Java compiler c. Java debugger d. Java API 4. Which of the following is true? a. Java uses only interpreter b. Java uses only compiler. c. Java uses both interpreter and compiler. d. None of the above. 5. A Java file with

IAS 36 – LỖ TỔN THẤT TÀI SẢN. xxx KHÔNG áp dụngcho Ápdụngcho x Hàng tồnkho (IAS 2) x . Tài sản tài chính (IFRS 9) x . Quyền lợi người lao động (IAS 19) x . Tài sản thuế hoãn lại (IAS 12) x . Hợp đồng xây dựng (IAS 11) x . Bất động s

2 Java Applications on Oracle Database 2.1 Database Sessions Imposed on Java Applications 2-1 2.2 Execution Control of Java Applications 2-3 2.3 Java Code, Binaries, and Resources Storage 2-3 2.4 About Java Classes Loaded in the Database 2-4 2.5 Preparing Java Class Methods for Execution 2-5 2.5.1 Compiling Java Classes 2-6

besteht aus der Java-API (Java Application Programming Interface) und der Java-VM (Java Virtual Machine). Abbildung 1: Java-Plattform Die Java-API ist eine große Sammlung von Java-Programmen, die in sog. Pakete (packages) aufgeteilt sind. Pakete sind vergleichbar mit Bibliotheken in anderen Programmiersprachen und umfassen u.a.

JAR Javadoc Java Language jar Security Others Toolkits: FX Java 2D Sound . Java Programming -Week 1. 6/25. Outline Java is. Let’s get started! The JDK The Java Sandbox . into your namespace. java.lang contains the most basic classes in the Java language. It is imported automatically, so

MONDAY 11TH JANUARY, 2021 AT 6.00 PM VENUE VIRTUAL MEETING Dear Councillors, Please find enclosed additional papers relating to the following items for the above mentioned meeting which were not available at the time of collation of the agenda. Item No Title of Report Pages 1. FAMILY SERVICES QUARTERLY UPDATE 3 - 12 Naomi Kwasa 020 8359 6146 naomi.kwasa@Barnet.gov.uk Please note that this will .