29
STATIC PROBLEMS DETECTION Overview and Tool Demonstration Kamil Ježek [email protected] Přemek Brada [email protected] Západočeská univerzita v Plzni Katedra informatiky a výpočetní techniky

Static program analysis tools

Embed Size (px)

Citation preview

Page 1: Static program analysis tools

STATIC PROBLEMS

DETECTION Overview and Tool Demonstration

Kamil Ježek [email protected]

Přemek Brada [email protected]

Západočeská univerzita v Plzni

Katedra informatiky a výpočetní techniky

Page 2: Static program analysis tools

What We Detect

LinkageError ClassCastException

NoSuchMethodError

IncompatibleClassChangeError

and more Recompilable problems

Duplicated and redundant libraries

Page 3: Static program analysis tools

Brief Example

LineIterator it = ... String line = it.next();

class LineIterator { Object next(); }

Page 4: Static program analysis tools

Where We Detect Problems

• Binaries (modules, libraries)

Source

code

Page 5: Static program analysis tools

Is This Real Problem?

75% of programs

riddled with static errors

Page 6: Static program analysis tools

Probable Cause

51% developers

unfamiliar with problem

Page 7: Static program analysis tools

Compatibility May Be Tricky

public class Main {

public static void main(String[] args) {

Object n = new LineIterator().next();

}

}

public class LineIterator {

public String next() {

return …;

}

}

Page 8: Static program analysis tools

JVM and Compiler Differences

public class Main {

public static void main(String[] args) {

LineIterator it = …

Object n = it.next();

}

}

public class LineIterator {

public Object next() {

return …;

}

}

public interface LineIterator {

public Object next();

}

v1 v2

Page 9: Static program analysis tools

Evidence in Real Life Software

Popular projects • Apache Roller

• Commons-IO

Even Maven is not answer

Page 10: Static program analysis tools

Example 1: Apache Roller

Apache Roller links to two httpcore versions

Page 11: Static program analysis tools

Impact on Apache Roller

Method releaseConnection() invoked by

Spring-web missing in httpcore 4.1

• Reported and acknowledged

Page 12: Static program analysis tools

Example 2: Apache Commons-io

Commons-io is distributed in two packages

Page 13: Static program analysis tools

Impact of Apache Commons-IO

Maven Central Repository

org.apache.commons used by 542 projects

commons-io used by 293 projects

Page 14: Static program analysis tools

We Propose Solution

JAR files Reverse

Engineering Verification Report

Page 15: Static program analysis tools

Architecture

Another integration

Eclipse Plugin

Maven Plugin

Backward Compatibility

Composition Verification

Reverse Engineering

Page 16: Static program analysis tools

Detected Problems

● Missing dependencies (1)

● Inconsistent dependencies (2)

● Redundant dependencies (3)

● Duplicated dependencies (4)

Source code

(1)

(2)

(4)

(3)

Page 17: Static program analysis tools

Reverse Engineering

class LineIterator {

Object next(...) { … }

}

class Client {

private iterate(...) {

LineIterator it = IOUtils.lineIterator(…);

while (it.hasNext()) {

String data = it.next();

}

Consumer Changed in 2.x Provider

<<Class>>

LineIterator

<<Method>>

next

<<Return>>

Object

<<Class>>

LineIterator

<<Method>>

next

<<Return>>

String

Page 18: Static program analysis tools

Verification

>

<

=

?

Consumer Provider

<<Class>>

LineIterator

<<Method>>

next

<<Return>>

Object

<<Class>>

LineIterator

<<Method>>

next

<<Return>>

String

Page 19: Static program analysis tools

Impact Demonstration

• Problem with duplicated Commons-IO

• Based on semi-real Booking web application

Page 20: Static program analysis tools

Web Page With Bug

Page 21: Static program analysis tools

Standard Debug I

Page 22: Static program analysis tools

Standard Debug II

• Log analysis (when enabled)

2015-04-15 17:17:58.538 WARN [org.eclipse.jetty.util.thread.QueuedThreadPool:run:577] -

java.lang.NoSuchMethodError: org.apache.commons.io.LineIterator.next()Ljava/lang/String;

at cz.zcu.kiv.examples.booking.preferences.RatingLoader.load(RatingLoader.java:29)

at cz.zcu.kiv.examples.booking.server.RunServer$2.handle(RunServer.java:53)

at spark.webserver.MatcherFilter.doFilter(MatcherFilter.java:139)

at spark.webserver.JettyHandler.doHandle(JettyHandler.java:54)

Page 23: Static program analysis tools

Our Way: Maven plugin • > mvn install

cz.zcu.kiv.examples.booking.preferences.RatingLoader

#4 <>-- org.apache.commons.io.LineIterator

Method: next

Generalised Return type: java.lang.String x java.lang.Object

=============================================================

Duplicated <>-- org.apache.commons.io.LineIterator

#5 /../.m2/repository/../commons-io-1.3.2.jar

-> #4

#6 /../.m2/repository/../commons-io-2.1.jar

---------------------------------------------------------------------------------

Must remove /../.m2/repository/../commons-io-1.3.2.jar

-> #5

---------------------------------------------------------------------------------

Redundant /../.m2/repository/../jetty-security-9.0.2.v20130417.jar

Page 24: Static program analysis tools

Eclipse Plugin

Page 25: Static program analysis tools

Easy to Fix Now

<dependency>

<groupId>commons-io</groupId>

<artifactId>commons-io</artifactId>

<version>1.3.2 2.1</version>

<type>jar</type>

<scope>compile</scope>

</dependency>

Page 26: Static program analysis tools

Result is Working System

Page 27: Static program analysis tools

We Offer

• Presented tools

• Customization

• Development of new features

Page 28: Static program analysis tools

Conclusion

• Automatic tools

• Problems detected early in development

• Solve current problems

• Cheaper and more robust software

Page 29: Static program analysis tools

Discussion

Questions now

or

Kamil Ježek [email protected]

Přemek Brada [email protected]

Západočeská univerzita v Plzni

Katedra informatiky a výpočetní techniky