ModiChecker : Accessibility Excessiveness Analysis Tool

Download Report

Transcript ModiChecker : Accessibility Excessiveness Analysis Tool

ModiChecker : Accessibility
Excessiveness Analysis
Tool for Java Program
Dotri Quoc†, Kazuo Kobori†, Norihiro Yoshida*,
Yoshiki Higo† , Katsuro Inoue†
† : Osaka University, Japan
* : Nara Institute of Science and Technology , Japan
Department of Computer Science,
Graduate School of Information Science & Technology,
Osaka University
1
Outline
 Introduction
 AE
Analysis Tool : ModiChecker
 Experiment and Discussion
 Conclusion and future work
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
2
Encapsulation in Java Programming
One characteristic of object oriented
programming
 Object’s code and data is hidden from other
objects

 Interface
encapsulates objects’ code and data
Good Encapsulation : choosing appropriate
access modifier for fields/methods
 Bad habit of Access Modifier setting : public
or default(no explicit declaration)

JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
3
Example of Bad Access Modifier
Declaration- Binary Search
CLASS1
Sorting Array A in
int[] A ;
an order
…..
public void sort(){
…
Searching
}
public int binarySearch(int value){
//Find index of value in array
…
Private
}
public void process(){
int x;
// set value of x from some where
….
this.sort() ;
int index = this.binarySearch(x) ;
// other operation with index ;
…
}
JSSST11
CLASS2
Set value for
array object.A
public void process{
CLASS1 object = new CLASS1() ;
…
//searching a value in array without sorting
int index = object.binarySearch(10) ;
}
Calling
sort
binarySearch
Order
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
4
AE : Accessibility Excessiveness(1/2)

AE : Discrepancy between declared access
modifier and actual usage
 An AE could caused unwilling access to
method/field
 AE could be used as an indicator of immaturity of
developer
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
5
AE : Accessibility Excessiveness(2/2)

Acquirement of AE for each field/method
 AE
causes bug in latter development and
maintenance phase
AE analysis tool : ModiChecker
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
6
Outline
 Introduction
 AE
Analysis Tool : ModiChecker
 Experiment and Discussion
 Conclusion and future work
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
7
AE Analysis Tool : ModiChecker

AE analysis for Java Program
 Report

excessiveness for each field/method
Requirement for implementation :
 Access
Modifiers declaration and actual usage
of field/method from other objects
 AE Map : define all cases of AE
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
8
Approach to AE Analysis
Static Source Code Analysis

Requirement
 Information of each field/method’s access
modifier declaration
 Actual Usage of each field/method
Static source code Analysis is required
Employing MASU

MASU : Platform for Metrics measurement but is
useful as a Java program analysis framework
MASU - http://sourceforge.net/projects/masu/
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
9
Approach to AE Analysis-AE Map (1/2)

Java Access Modifier
 Public
: can be accessed by all classes
 Protected: can be only accessed by classes in
the same package and subclasses
 Default :can be only accessed by classes in the
same package.
 No
explicit Access Modifier is declared
 Private:
can be only accessed from inside of
owner class
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
10
Approach to AE Analysis-AE Map (2/2)
Accessibility Excessive Map
AE Id
AE Id of Excessive
Actual Usage fields/methods
Syntax Error
Public
Protected
Default
Private
ok-pub0
pub1
pub2
pub3
-
ok-pro0
pro1
pro2
Default
-
-
ok-def0
def1
Private
-
-
-
ok-pri0
Declaration
Public
Protected
JSSST11
No
Discrepancy
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
11
Architecture of ModiChecker
Input
ModiChecker
MASU
Source Code
Source Code
Analyzer
Required
Library(.jar
files)
AST Database
Extraction of access
modifier declaration
Extraction of
method/field usage
Detection of declaration
excessiveness
Report of AE Id for each method/field
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
12
Special Cases for ModiChecker
No report for methods of Abstract classes
and Interfaces
 Method overriding an other method case

 overriding
method must have an access
modifier equal or more permissive level to the
access modifier of the overridden method
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
13
Example of Method Overriding
Method Case
Class A
public method C()
Class B
Access
modifier
of C must
be public

public method C()
Even if method B.C was only accessed from
inside class B, ModiChecker still reported
method B.C the AE Id of pub0
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
14
Outline
 Introduction
 AE
Analysis Tool : ModiChecker
 Experiment and Discussion
 Conclusion
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
15
Overview of Experiment(1/2)

Objectives of experiment
 Validation
of our approach
 Quantitative analysis of AE Id in open source
code
 Reasons
1.
2.
3.
for excessiveness
Reason 1 : Set for future use
Reason 2 : Created by other program(automatic
code generators or refactoring tools…)
Reason 3 : Carelessness and immaturity
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
16
Overview of Experiment(2/2)

Target Software
 Ant
1.8.2 (1141 files, 127235 LOC)
 jEdit 4.4.1(546 files, 109479 LOC)
 MASU(519 files, 10200 LOC)
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
17
Result of Ant(1/2)
Ratio of each AE Id
Field
Method
Excessive
pub2
pub1
Ok-xxx
pub3
Excessive
Ok-xxx
pro1
pub1
pro2
pub2
def1
18.9%
pri0
pub3
pub0
35.5%
pro0
def0
81.1%
def0
pro1
pro0
64.5%
pro2
pri0
def1
pub0
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
18
Result of Ant(2/2)

Excessive fields

Total number : 611(18.9%)
1.
2.
3.

Excessive methods

Total number : 1520(35.5%)
1.
2.
3.

Set for future use : unknown
Created by other program : 0
Carelessness and immaturity : unknown
Set for future use : unknown
Created by other program : 0
Carelessness and immaturity : unknown
Ratio of excessive methods > ratio of excessive fields

Encapsulation : Make fields private and provide public getter/setter
to access fields
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
19
Result of jEdit(1/2)
Ratio of each AE Id
Fields
Excessive
Methods
Ok-xxx
pub2
pub1
Excessive
pub3 pro1
Ok-xxx
pub1
pub2
pro2
pri0
pri0
pub3
24.1%
def1
30.4%
pro1
pub0
75.9%
pro0
pro2
def0
def0
pro0
JSSST11
69.6
def1
pub0
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
20
Result of jEdit(2/2)

Excessive fields
 Total number : 604(24.1%)
1.
2.
3.

Excessive methods
 Total number : 981(30.4%)
1.
2.
3.

Set for future use : unknown
Created by other program : 0
Carelessness and immaturity : unknown
Set for future use : unknown
Created by other program : 0
Carelessness and immaturity : unknown
Ratio of excessive methods > ratio of excessive fields
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
21
Result of MASU(1/2)
Ratio of each AE Id
Fields
Excessive
Methods
Ok-xxx
Excessive
Ok-xxx
pub2
pub2
pub1
pub3
pub3
pri0
pro2
pri0
def1
35.7%
14.3%
pro1
pub0
64.3%
pro2
pub0
JSSST11
def1
85.7%
pro0
def0
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
22
Result of MASU(2/2)

Excessive fields
 Total number : 280(35.7%)
1.
2.
3.

Excessive methods
 Total number : 253(14.3%)
1.
2.
3.

Set for future use : 20
Created by other program(automatic code generator) : 255
Carelessness and immaturity : 5
Set for future use : 181
Created by other program(automatic code generator) : 6
Carelessness and immaturity : 66
Ratio of excessive fields > ratio of excessive methods
 Caused by fields created by automatic code generator
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
23
Discussion(1/3)

Validation of ModiChecker output
 Change
all of the excessive access modifier by
hand
 Modified
programs were compiled and executed
without any error
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
24
Discussion(2/3)

Solution for excessiveness
 Reason
1 : Excessiveness set for future use
requirement of tool which let developer select
fields/methods to change access modifier
 Reason
2 : Excessiveness created by other
programs
Using ModiChecker after using refactoring tools or
automatic code generating tools
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
25
Discussion(3/3)

Proposal of new quality metrics
 AE
index for each AE id and metrics value is
total of AE index of all methods/fields
 Set value for each field/method based on the
number of potential unexpected access. Metrics
value is total of those values.
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
26
Outline
 Introduction
 AE
Analysis Tool : ModiChecker
 Experiment and Discussion
 Conclusion and future work
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
27
Conclusion

Analysis method named AE for each field/method
 ModiChecker : find excessiveness and report AE
of each field/method
 Experiment on some open softwares
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
28
Future works
Apply ModiChecker for other Java systems
and other programming language
system(C# , C++…)
 AE analysis result and other program quality
indicators such as bug frequency

JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
29
THANK YOU FOR YOUR ATTENTION
JSSST11
2015/7/16
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
30