SlideShare uma empresa Scribd logo
1 de 31
Baixar para ler offline
Unusual Java Bugs
 and Fighting them Using FOSS Tools


                   S G Ganesh
                 Research Engineer
      Siemens (Corporate Technology), Bangalore



                               Open Source India W eek
              The TechZone: Developer Track—Bangalore
                                           12-Feb-2008
Why Static Analysis Tools

   Too much buggy software out there in the
    market
     Open    source is better, but still …
   Important to improve the quality of the
    software
     “ilities”   : reliability, security, maintainability etc.
   Testing is not enough
     Cannot       check all paths, possibilities, practices
Why Static Analysis Tools (contd..)
   Benefits of Static Analysis Tools
       Can cover code not covered by testing or dynamic
        analysis
       No instrumentation needed, no tests to develop and run
       Usually easy to use
            Run in your IDE, by just clicking a button
   Code review is not sufficient
       Can catch usual/obvious mistakes
       A static analysis tool can often find unusual bugs
Why Bugs Happen in Code?

   Everyone makes mistakes
          Including experts
          only that novices make more mistakes

   Compiler catches syntax/(some) semantic
    errors
       Not sufficient. E.g. how about errors in usage?
   We are often asked to ‘Get-the-code-
    working’
        So, after that, we spend rest of the time fixing
        the bugs ;-)
Why Java FOSS Tools?

   Many high quality FOSS tools available
     Java is free and widely used
     Java programs also suffer quality issues like
     code developed in C/C++
          No pointers, automatic memory management etc
          helps less experienced programmers much
         Still, Java software suffers quality problems like

          security, maintainability etc.
       Significantly improve quality of software
           before software is tested or released to users
Finding Uncommon Bugs

   We’ll see a buggy code example
     not usual bug like null pointer access or bad
     cast
     unusual bugs like misuse of language features,
     synchronization issues etc.
… and then see how a FOSS static
 analysis tool catches it
 We’ll see simple bugs first
       … and then move on to more difficult ones
What does this code print?

class LongVal {
     public static void main(String []s) {
          long l = 0x1l;
          System.out.format(quot;%xquot;, l);
     }
}
Here is the output …

   $ java LongVal
    1
    $
   The program prints 1 and not 11 – why?
Bug: ‘l’ and ‘1’ looks alike!

 The antic tool detects it:
$antic –java LongVal.java
LongVal.java:3:26: May be 'l' is used
  instead of '1' at the end of integer
  constant
 Programmer, possibly by mistake, typed
  ‘l’ (english letter ell) instead of ‘1’ (number
  one)!
  long l = 0x1l;
Introducing Jlint/Antic
   Antic is meant for finding problems related to C
    syntax
     Like this problem we saw now
     Works on java source files

   Jlint is for Java inconsistencies and bugs
     Can find difficult synchronization issues also
     Works on built class files

   Simple to use tool
       Used from command line
   Available from http://jlint.sourceforge.net
What does this code print?
 class NaNTest {
     public static void main(String []s) {
           double d = getVal();
           if(d == Double.NaN)
                   System.out.println(quot;d is NaNquot;);
     }
     private static double getVal() {
           return Double.NaN;
     }
 }
Here is the output…
  $ java NaNTest
  $
 It does not print anything!
FindBugs Detects it
Bug: (NaN == NaN) is false!
  FindBugs   names this bug as: “Doomed test for
   equality to NaN”
  This code checks to see if a floating point value
   is equal to the special Not A Number value (d ==
   Double.NaN).
  special semantics of NaN: no value is equal to
   NaN, including NaN.
  d == Double.NaN is always false

  Correct check: Use Double.isNaN(x)
Introducing FingBugs

 Detects problems like correctness,
  multithreading issues, performance
  problems, bad practices etc
 Less number of false positives
 No source files needed
     Runs   on Java class/jar files
   You can run it on huge code-bases
     Runs   in a nice GUI
   Get from: http://findbugs.sourceforge.net/
How FindBugs GUI looks
What is wrong with this code?
Here is the output…
PMD Detects It
   $pmd Test.java text design
    Test.java:3 Overridable method 'foo'
    called during object construction
Bug: Ctor calls overridden method!

   Constructors   do not support runtime
    polymorphism
   Because derived objects are not constructed yet
    when base class constructor executes.
   Virtual method foo is called from the base class
    constructor
   Overridden foo calls toString method from i
    which is not initialized yet
   Results in NullPointerException
Introducing PMD
   PMD checks for problems like:
     Possible bugs, design rule violations
     Duplicate, sub-optimal or dead code

     Suggestions for Migration to newer JDK versions,
      J2EE, JavaBeans, JSP, JUnit rules
   Works on Java source files
   Command-line
       Or as plugin for Eclipse, JBuilder, JCreator etc.
   Get from: http://pmd.sourceforge.net/
What is wrong with this code?
What is wrong with this code? …
Here is the output…
 The program hangs after running
  successfully for few times
 It ‘deadlocked’..
QJ-Pro Detects It
Bug: Multiple locks can deadlock!
  Locks:    basic Java synchronization mechanism
       Ensures exclusive ownership for a thread while
        executing critical section
  Incorrect
           synchronization can lead to deadlocks
  Deadlocks are ‘non-deterministic’
       Hence difficult to detect, reproduce and fix
  Acquiring    multiple locks is prone to deadlock
     Particularly if not done in same order
     or if sleep() in Thread is called

  Inthis program, foo and bar acquire locks in
   opposite order and hence deadlock occurs
Introducing QJ-Pro
   QJ-Pro checks for problems like:
     Conformance to coding standards, coding best
      practices
     Misuse of features, APIs etc

   Works on Java source files
   Easy to use in standalone GUI version
       Or Eclipse, JBuilder, JDeveloper plugins or Ant job
   Get from: http://qjpro.sourceforge.net/
How QJ-Pro GUI looks
Other FOSS Java Tools
  CheckStyle
      Checks for adherance to coding standards such as
       Sun’s
      Get it from http://checkstyle.sourceforge.net/

    JCSC (Java Coding Style Checker)
      Checks for coding style adherance &
      … and also checks for common bugs

      Get it from http://checkstyle.sourceforge.net/

  There     are many more
        Classycle, Condenser, DoctorJ, JarAnalyzer…
Banish the Bug!
  Tools   are free
      why don’t you use it for getting rid of bugs
  Ensure    high-quality of software
      By detecting and fixing bugs early in s/w lifecycle
Thank You!
   Some Links:
     Code    Snippet Of the Day (CodeSOD)
          http://thedailywtf.com/Series/CodeSOD.aspx
     List   of Open Source Java code analyzers
          http://java-source.net/open-source/code-analyzers


   Enough bugging you!
     Time    for Q & A now

Mais conteúdo relacionado

Mais procurados

Static code analysis
Static code analysisStatic code analysis
Static code analysisRune Sundling
 
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,..."Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...Vladimir Ivanov
 
Realtime selenium interview questions
Realtime selenium interview questionsRealtime selenium interview questions
Realtime selenium interview questionsKuldeep Pawar
 
How Spotify Does Test Automation - Kristian Karl
How Spotify Does Test Automation - Kristian KarlHow Spotify Does Test Automation - Kristian Karl
How Spotify Does Test Automation - Kristian KarlSmartBear
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven DevelopmentPablo Villar
 
Sonar Tool - JAVA code analysis
Sonar Tool - JAVA code analysisSonar Tool - JAVA code analysis
Sonar Tool - JAVA code analysisPrashant Gupta
 
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021Victor Rentea
 
Practical Test Automation Deep Dive
Practical Test Automation Deep DivePractical Test Automation Deep Dive
Practical Test Automation Deep DiveAlan Richardson
 
Model-based Testing: Taking BDD/ATDD to the Next Level
Model-based Testing: Taking BDD/ATDD to the Next LevelModel-based Testing: Taking BDD/ATDD to the Next Level
Model-based Testing: Taking BDD/ATDD to the Next LevelBob Binder
 
If you want to automate, you learn to code
If you want to automate, you learn to codeIf you want to automate, you learn to code
If you want to automate, you learn to codeAlan Richardson
 
How to become a .net debugging jedi (Microsoft R&D Center, Nazareth, Israel)
How to become a .net debugging jedi (Microsoft R&D Center, Nazareth, Israel)How to become a .net debugging jedi (Microsoft R&D Center, Nazareth, Israel)
How to become a .net debugging jedi (Microsoft R&D Center, Nazareth, Israel)Moaid Hathot
 
Php Debugging from the Trenches
Php Debugging from the TrenchesPhp Debugging from the Trenches
Php Debugging from the TrenchesSimon Jones
 
Proper Null handling with modern java techniques
Proper Null handling with modern java techniquesProper Null handling with modern java techniques
Proper Null handling with modern java techniquesNikola Petrov
 
Extreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software CraftsmanshipExtreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software CraftsmanshipVictor Rentea
 
Keyword Driven Testing
Keyword Driven TestingKeyword Driven Testing
Keyword Driven TestingMaveryx
 

Mais procurados (20)

Static code analysis
Static code analysisStatic code analysis
Static code analysis
 
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,..."Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
 
Realtime selenium interview questions
Realtime selenium interview questionsRealtime selenium interview questions
Realtime selenium interview questions
 
Test Automation and Keyword-driven testing af Brian Nielsen, CISS/AAU
Test Automation and Keyword-driven testing af Brian Nielsen, CISS/AAUTest Automation and Keyword-driven testing af Brian Nielsen, CISS/AAU
Test Automation and Keyword-driven testing af Brian Nielsen, CISS/AAU
 
How Spotify Does Test Automation - Kristian Karl
How Spotify Does Test Automation - Kristian KarlHow Spotify Does Test Automation - Kristian Karl
How Spotify Does Test Automation - Kristian Karl
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
Sonar Tool - JAVA code analysis
Sonar Tool - JAVA code analysisSonar Tool - JAVA code analysis
Sonar Tool - JAVA code analysis
 
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
 
Practical Test Automation Deep Dive
Practical Test Automation Deep DivePractical Test Automation Deep Dive
Practical Test Automation Deep Dive
 
Model-based Testing: Taking BDD/ATDD to the Next Level
Model-based Testing: Taking BDD/ATDD to the Next LevelModel-based Testing: Taking BDD/ATDD to the Next Level
Model-based Testing: Taking BDD/ATDD to the Next Level
 
Testing 101
Testing 101Testing 101
Testing 101
 
Java Code Quality Tools
Java Code Quality ToolsJava Code Quality Tools
Java Code Quality Tools
 
Static Code Analysis
Static Code AnalysisStatic Code Analysis
Static Code Analysis
 
If you want to automate, you learn to code
If you want to automate, you learn to codeIf you want to automate, you learn to code
If you want to automate, you learn to code
 
Greach 2015 Spock workshop
Greach 2015 Spock workshopGreach 2015 Spock workshop
Greach 2015 Spock workshop
 
How to become a .net debugging jedi (Microsoft R&D Center, Nazareth, Israel)
How to become a .net debugging jedi (Microsoft R&D Center, Nazareth, Israel)How to become a .net debugging jedi (Microsoft R&D Center, Nazareth, Israel)
How to become a .net debugging jedi (Microsoft R&D Center, Nazareth, Israel)
 
Php Debugging from the Trenches
Php Debugging from the TrenchesPhp Debugging from the Trenches
Php Debugging from the Trenches
 
Proper Null handling with modern java techniques
Proper Null handling with modern java techniquesProper Null handling with modern java techniques
Proper Null handling with modern java techniques
 
Extreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software CraftsmanshipExtreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software Craftsmanship
 
Keyword Driven Testing
Keyword Driven TestingKeyword Driven Testing
Keyword Driven Testing
 

Destaque (7)

10 Inspiring Quotes That Can Change Your Life
10 Inspiring Quotes That Can Change Your Life 10 Inspiring Quotes That Can Change Your Life
10 Inspiring Quotes That Can Change Your Life
 
Migrating From Cpp To C Sharp
Migrating From Cpp To C SharpMigrating From Cpp To C Sharp
Migrating From Cpp To C Sharp
 
Generic Programming
Generic ProgrammingGeneric Programming
Generic Programming
 
10 Best Quotes of Steve Jobs
10 Best Quotes of Steve Jobs10 Best Quotes of Steve Jobs
10 Best Quotes of Steve Jobs
 
Stl
StlStl
Stl
 
14 Late X
14 Late X14 Late X
14 Late X
 
Java Generics - Quiz Questions
Java Generics - Quiz QuestionsJava Generics - Quiz Questions
Java Generics - Quiz Questions
 

Semelhante a Presentations Unusual Java Bugs And Detecting Them Using Foss Tools

How the JDeveloper team test JDeveloper at UKOUG'08
How the JDeveloper team test JDeveloper at UKOUG'08How the JDeveloper team test JDeveloper at UKOUG'08
How the JDeveloper team test JDeveloper at UKOUG'08kingsfleet
 
Building a JavaScript Library
Building a JavaScript LibraryBuilding a JavaScript Library
Building a JavaScript Libraryjeresig
 
Ten Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project ExperiencesTen Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project ExperiencesHenrik Olsson
 
Static Analysis Techniques For Testing Application Security - Houston Tech Fest
Static Analysis Techniques For Testing Application Security - Houston Tech FestStatic Analysis Techniques For Testing Application Security - Houston Tech Fest
Static Analysis Techniques For Testing Application Security - Houston Tech FestDenim Group
 
Ajax Tutorial
Ajax TutorialAjax Tutorial
Ajax Tutorialoscon2007
 
Generic Attack Detection - ph-Neutral 0x7d8
Generic Attack Detection - ph-Neutral 0x7d8Generic Attack Detection - ph-Neutral 0x7d8
Generic Attack Detection - ph-Neutral 0x7d8Mario Heiderich
 
Here Be Dragons – Advanced JavaScript Debugging
Here Be Dragons – Advanced JavaScript DebuggingHere Be Dragons – Advanced JavaScript Debugging
Here Be Dragons – Advanced JavaScript DebuggingFITC
 
FITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingFITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingRami Sayar
 
Secure Programming With Static Analysis
Secure Programming With Static AnalysisSecure Programming With Static Analysis
Secure Programming With Static AnalysisConSanFrancisco123
 
Scripting Recipes for Testers
Scripting Recipes for TestersScripting Recipes for Testers
Scripting Recipes for TestersAdam Goucher
 
Creating a reasonable project boilerplate
Creating a reasonable project boilerplateCreating a reasonable project boilerplate
Creating a reasonable project boilerplateStanislav Petrov
 
Javascript Framework Roundup FYB
Javascript Framework Roundup FYBJavascript Framework Roundup FYB
Javascript Framework Roundup FYBnukeevry1
 
Web a Quebec - JS Debugging
Web a Quebec - JS DebuggingWeb a Quebec - JS Debugging
Web a Quebec - JS DebuggingRami Sayar
 
Unit Testing & Test Driven Development
Unit Testing & Test Driven DevelopmentUnit Testing & Test Driven Development
Unit Testing & Test Driven Developmentersanbilik
 
Automated Performance Testing With J Meter And Maven
Automated  Performance  Testing With  J Meter And  MavenAutomated  Performance  Testing With  J Meter And  Maven
Automated Performance Testing With J Meter And MavenPerconaPerformance
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsLuís Bastião Silva
 
javabasics_ programming development chapter01
javabasics_ programming development chapter01javabasics_ programming development chapter01
javabasics_ programming development chapter01Udeshg90
 

Semelhante a Presentations Unusual Java Bugs And Detecting Them Using Foss Tools (20)

How the JDeveloper team test JDeveloper at UKOUG'08
How the JDeveloper team test JDeveloper at UKOUG'08How the JDeveloper team test JDeveloper at UKOUG'08
How the JDeveloper team test JDeveloper at UKOUG'08
 
Jdj Foss Java Tools
Jdj Foss Java ToolsJdj Foss Java Tools
Jdj Foss Java Tools
 
Building a JavaScript Library
Building a JavaScript LibraryBuilding a JavaScript Library
Building a JavaScript Library
 
Ten Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project ExperiencesTen Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project Experiences
 
Static Analysis Techniques For Testing Application Security - Houston Tech Fest
Static Analysis Techniques For Testing Application Security - Houston Tech FestStatic Analysis Techniques For Testing Application Security - Houston Tech Fest
Static Analysis Techniques For Testing Application Security - Houston Tech Fest
 
Ajax Tutorial
Ajax TutorialAjax Tutorial
Ajax Tutorial
 
Generic Attack Detection - ph-Neutral 0x7d8
Generic Attack Detection - ph-Neutral 0x7d8Generic Attack Detection - ph-Neutral 0x7d8
Generic Attack Detection - ph-Neutral 0x7d8
 
PHP - Introduction to PHP Bugs - Debugging
PHP -  Introduction to  PHP Bugs - DebuggingPHP -  Introduction to  PHP Bugs - Debugging
PHP - Introduction to PHP Bugs - Debugging
 
Here Be Dragons – Advanced JavaScript Debugging
Here Be Dragons – Advanced JavaScript DebuggingHere Be Dragons – Advanced JavaScript Debugging
Here Be Dragons – Advanced JavaScript Debugging
 
FITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingFITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript Debugging
 
Secure Programming With Static Analysis
Secure Programming With Static AnalysisSecure Programming With Static Analysis
Secure Programming With Static Analysis
 
Scripting Recipes for Testers
Scripting Recipes for TestersScripting Recipes for Testers
Scripting Recipes for Testers
 
Creating a reasonable project boilerplate
Creating a reasonable project boilerplateCreating a reasonable project boilerplate
Creating a reasonable project boilerplate
 
Javascript Framework Roundup FYB
Javascript Framework Roundup FYBJavascript Framework Roundup FYB
Javascript Framework Roundup FYB
 
Web a Quebec - JS Debugging
Web a Quebec - JS DebuggingWeb a Quebec - JS Debugging
Web a Quebec - JS Debugging
 
Unit Testing & Test Driven Development
Unit Testing & Test Driven DevelopmentUnit Testing & Test Driven Development
Unit Testing & Test Driven Development
 
Automated Performance Testing With J Meter And Maven
Automated  Performance  Testing With  J Meter And  MavenAutomated  Performance  Testing With  J Meter And  Maven
Automated Performance Testing With J Meter And Maven
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.js
 
javabasics_ programming development chapter01
javabasics_ programming development chapter01javabasics_ programming development chapter01
javabasics_ programming development chapter01
 
Tdd - introduction
Tdd - introductionTdd - introduction
Tdd - introduction
 

Mais de Ganesh Samarthyam

Applying Refactoring Tools in Practice
Applying Refactoring Tools in PracticeApplying Refactoring Tools in Practice
Applying Refactoring Tools in PracticeGanesh Samarthyam
 
CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”Ganesh Samarthyam
 
Great Coding Skills Aren't Enough
Great Coding Skills Aren't EnoughGreat Coding Skills Aren't Enough
Great Coding Skills Aren't EnoughGanesh Samarthyam
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionGanesh Samarthyam
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeGanesh Samarthyam
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesGanesh Samarthyam
 
Bangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief PresentationBangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief PresentationGanesh Samarthyam
 
Bangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - PosterBangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - PosterGanesh Samarthyam
 
Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)Ganesh Samarthyam
 
OO Design and Design Patterns in C++
OO Design and Design Patterns in C++ OO Design and Design Patterns in C++
OO Design and Design Patterns in C++ Ganesh Samarthyam
 
Bangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship DeckBangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship DeckGanesh Samarthyam
 
Let's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageLet's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageGanesh Samarthyam
 
Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Ganesh Samarthyam
 
Software Architecture - Quiz Questions
Software Architecture - Quiz QuestionsSoftware Architecture - Quiz Questions
Software Architecture - Quiz QuestionsGanesh Samarthyam
 
Core Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quizCore Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quizGanesh Samarthyam
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesGanesh Samarthyam
 

Mais de Ganesh Samarthyam (20)

Wonders of the Sea
Wonders of the SeaWonders of the Sea
Wonders of the Sea
 
Animals - for kids
Animals - for kids Animals - for kids
Animals - for kids
 
Applying Refactoring Tools in Practice
Applying Refactoring Tools in PracticeApplying Refactoring Tools in Practice
Applying Refactoring Tools in Practice
 
CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”
 
Great Coding Skills Aren't Enough
Great Coding Skills Aren't EnoughGreat Coding Skills Aren't Enough
Great Coding Skills Aren't Enough
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - Description
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean Code
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 
Bangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief PresentationBangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief Presentation
 
Bangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - PosterBangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - Poster
 
Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)
 
OO Design and Design Patterns in C++
OO Design and Design Patterns in C++ OO Design and Design Patterns in C++
OO Design and Design Patterns in C++
 
Bangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship DeckBangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship Deck
 
Let's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageLet's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming Language
 
Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Software Architecture - Quiz Questions
Software Architecture - Quiz QuestionsSoftware Architecture - Quiz Questions
Software Architecture - Quiz Questions
 
Docker by Example - Quiz
Docker by Example - QuizDocker by Example - Quiz
Docker by Example - Quiz
 
Core Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quizCore Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quiz
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java Bytecodes
 

Último

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 

Último (20)

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 

Presentations Unusual Java Bugs And Detecting Them Using Foss Tools

  • 1. Unusual Java Bugs and Fighting them Using FOSS Tools S G Ganesh Research Engineer Siemens (Corporate Technology), Bangalore Open Source India W eek The TechZone: Developer Track—Bangalore 12-Feb-2008
  • 2. Why Static Analysis Tools  Too much buggy software out there in the market  Open source is better, but still …  Important to improve the quality of the software  “ilities” : reliability, security, maintainability etc.  Testing is not enough  Cannot check all paths, possibilities, practices
  • 3. Why Static Analysis Tools (contd..)  Benefits of Static Analysis Tools  Can cover code not covered by testing or dynamic analysis  No instrumentation needed, no tests to develop and run  Usually easy to use  Run in your IDE, by just clicking a button  Code review is not sufficient  Can catch usual/obvious mistakes  A static analysis tool can often find unusual bugs
  • 4. Why Bugs Happen in Code?  Everyone makes mistakes  Including experts  only that novices make more mistakes  Compiler catches syntax/(some) semantic errors  Not sufficient. E.g. how about errors in usage?  We are often asked to ‘Get-the-code- working’  So, after that, we spend rest of the time fixing the bugs ;-)
  • 5. Why Java FOSS Tools?  Many high quality FOSS tools available  Java is free and widely used  Java programs also suffer quality issues like code developed in C/C++  No pointers, automatic memory management etc helps less experienced programmers much  Still, Java software suffers quality problems like security, maintainability etc.  Significantly improve quality of software  before software is tested or released to users
  • 6. Finding Uncommon Bugs  We’ll see a buggy code example  not usual bug like null pointer access or bad cast  unusual bugs like misuse of language features, synchronization issues etc. … and then see how a FOSS static analysis tool catches it  We’ll see simple bugs first  … and then move on to more difficult ones
  • 7. What does this code print? class LongVal { public static void main(String []s) { long l = 0x1l; System.out.format(quot;%xquot;, l); } }
  • 8. Here is the output …  $ java LongVal 1 $  The program prints 1 and not 11 – why?
  • 9. Bug: ‘l’ and ‘1’ looks alike!  The antic tool detects it: $antic –java LongVal.java LongVal.java:3:26: May be 'l' is used instead of '1' at the end of integer constant  Programmer, possibly by mistake, typed ‘l’ (english letter ell) instead of ‘1’ (number one)! long l = 0x1l;
  • 10. Introducing Jlint/Antic  Antic is meant for finding problems related to C syntax  Like this problem we saw now  Works on java source files  Jlint is for Java inconsistencies and bugs  Can find difficult synchronization issues also  Works on built class files  Simple to use tool  Used from command line  Available from http://jlint.sourceforge.net
  • 11. What does this code print? class NaNTest { public static void main(String []s) { double d = getVal(); if(d == Double.NaN) System.out.println(quot;d is NaNquot;); } private static double getVal() { return Double.NaN; } }
  • 12. Here is the output… $ java NaNTest $  It does not print anything!
  • 14. Bug: (NaN == NaN) is false!  FindBugs names this bug as: “Doomed test for equality to NaN”  This code checks to see if a floating point value is equal to the special Not A Number value (d == Double.NaN).  special semantics of NaN: no value is equal to NaN, including NaN.  d == Double.NaN is always false  Correct check: Use Double.isNaN(x)
  • 15. Introducing FingBugs  Detects problems like correctness, multithreading issues, performance problems, bad practices etc  Less number of false positives  No source files needed  Runs on Java class/jar files  You can run it on huge code-bases  Runs in a nice GUI  Get from: http://findbugs.sourceforge.net/
  • 17. What is wrong with this code?
  • 18. Here is the output…
  • 19. PMD Detects It  $pmd Test.java text design Test.java:3 Overridable method 'foo' called during object construction
  • 20. Bug: Ctor calls overridden method!  Constructors do not support runtime polymorphism  Because derived objects are not constructed yet when base class constructor executes.  Virtual method foo is called from the base class constructor  Overridden foo calls toString method from i which is not initialized yet  Results in NullPointerException
  • 21. Introducing PMD  PMD checks for problems like:  Possible bugs, design rule violations  Duplicate, sub-optimal or dead code  Suggestions for Migration to newer JDK versions, J2EE, JavaBeans, JSP, JUnit rules  Works on Java source files  Command-line  Or as plugin for Eclipse, JBuilder, JCreator etc.  Get from: http://pmd.sourceforge.net/
  • 22. What is wrong with this code?
  • 23. What is wrong with this code? …
  • 24. Here is the output…  The program hangs after running successfully for few times  It ‘deadlocked’..
  • 26. Bug: Multiple locks can deadlock!  Locks: basic Java synchronization mechanism  Ensures exclusive ownership for a thread while executing critical section  Incorrect synchronization can lead to deadlocks  Deadlocks are ‘non-deterministic’  Hence difficult to detect, reproduce and fix  Acquiring multiple locks is prone to deadlock  Particularly if not done in same order  or if sleep() in Thread is called  Inthis program, foo and bar acquire locks in opposite order and hence deadlock occurs
  • 27. Introducing QJ-Pro  QJ-Pro checks for problems like:  Conformance to coding standards, coding best practices  Misuse of features, APIs etc  Works on Java source files  Easy to use in standalone GUI version  Or Eclipse, JBuilder, JDeveloper plugins or Ant job  Get from: http://qjpro.sourceforge.net/
  • 28. How QJ-Pro GUI looks
  • 29. Other FOSS Java Tools  CheckStyle  Checks for adherance to coding standards such as Sun’s  Get it from http://checkstyle.sourceforge.net/  JCSC (Java Coding Style Checker)  Checks for coding style adherance &  … and also checks for common bugs  Get it from http://checkstyle.sourceforge.net/  There are many more  Classycle, Condenser, DoctorJ, JarAnalyzer…
  • 30. Banish the Bug!  Tools are free  why don’t you use it for getting rid of bugs  Ensure high-quality of software  By detecting and fixing bugs early in s/w lifecycle
  • 31. Thank You!  Some Links:  Code Snippet Of the Day (CodeSOD)  http://thedailywtf.com/Series/CodeSOD.aspx  List of Open Source Java code analyzers  http://java-source.net/open-source/code-analyzers  Enough bugging you!  Time for Q & A now