Java problems   Raw type parameters     Working with the Java compiler     Logging         Static analysis




                                          CS/SE Individual Practical


                                                      Stephen Gilmore
                                                     November 11, 2011
                                      School of Informatics, University of Edinburgh




                                                                         CS/SE Individual Practical
                                                                                                      1 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Java problems


                Common Java problems: raw types




                                                                       CS/SE Individual Practical
                                                                                                    2 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Java problems


                Quick fix: a bad suggestion




                                                                       CS/SE Individual Practical
                                                                                                    3 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Java problems


                Check the constructor documentation




                                                                       CS/SE Individual Practical
                                                                                                    4 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Java problems


                Check the class documentation




                                                                       CS/SE Individual Practical
                                                                                                    5 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Java problems


                What type of array are we adapting?




                                                                       CS/SE Individual Practical
                                                                                                    6 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Java problems


                Type parameter added




                                                                       CS/SE Individual Practical
                                                                                                    7 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Raw type parameters


                Raw type in method header




                                                                       CS/SE Individual Practical
                                                                                                    8 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Raw type parameters


                Consult the Java documentation




                                                                       CS/SE Individual Practical
                                                                                                    9 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Raw type parameters


                Adapter doesn’t work here




                                                                       CS/SE Individual Practical
                                                                                                    10 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Raw type parameters


                Adapter is an interface




                                                                       CS/SE Individual Practical
                                                                                                    11 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Raw type parameters


                T is not a class




                                                                       CS/SE Individual Practical
                                                                                                    12 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Raw type parameters


                Object: the goto class




                                                                       CS/SE Individual Practical
                                                                                                    13 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Raw type parameters


                T extends Adapter doesn’t work




                                                                       CS/SE Individual Practical
                                                                                                    14 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Raw type parameters


                “?” — the wild card parameter




                                                                       CS/SE Individual Practical
                                                                                                    15 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Raw type parameters


                “Quick fix” would have worked here




                                                                       CS/SE Individual Practical
                                                                                                    16 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Raw type parameters


                Same result




                                                                       CS/SE Individual Practical
                                                                                                    17 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Working with the Java compiler


                Setting Java compiler preferences




                                                                       CS/SE Individual Practical
                                                                                                    18 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Working with the Java compiler


                Changing defaults




                                                                       CS/SE Individual Practical
                                                                                                    19 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Working with the Java compiler


                Potential programming problems




                                                                       CS/SE Individual Practical
                                                                                                    20 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Working with the Java compiler


                Tighter checking




                                                                       CS/SE Individual Practical
                                                                                                    21 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Working with the Java compiler


                Bug found




                                                                       CS/SE Individual Practical
                                                                                                    22 / 24
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                    Logging


                    Don’t forget to add logging . . .




                                                                           CS/SE Individual Practical
                                                                                                        23 / 24
.41.02.png
Java problems   Raw type parameters   Working with the Java compiler     Logging         Static analysis
                Static analysis


                Deeper analysis (resource leaks . . . )




                                                                       CS/SE Individual Practical
                                                                                                    24 / 24

Fixing errors in Android Java applications

  • 1.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis CS/SE Individual Practical Stephen Gilmore November 11, 2011 School of Informatics, University of Edinburgh CS/SE Individual Practical 1 / 24
  • 2.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Java problems Common Java problems: raw types CS/SE Individual Practical 2 / 24
  • 3.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Java problems Quick fix: a bad suggestion CS/SE Individual Practical 3 / 24
  • 4.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Java problems Check the constructor documentation CS/SE Individual Practical 4 / 24
  • 5.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Java problems Check the class documentation CS/SE Individual Practical 5 / 24
  • 6.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Java problems What type of array are we adapting? CS/SE Individual Practical 6 / 24
  • 7.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Java problems Type parameter added CS/SE Individual Practical 7 / 24
  • 8.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Raw type parameters Raw type in method header CS/SE Individual Practical 8 / 24
  • 9.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Raw type parameters Consult the Java documentation CS/SE Individual Practical 9 / 24
  • 10.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Raw type parameters Adapter doesn’t work here CS/SE Individual Practical 10 / 24
  • 11.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Raw type parameters Adapter is an interface CS/SE Individual Practical 11 / 24
  • 12.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Raw type parameters T is not a class CS/SE Individual Practical 12 / 24
  • 13.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Raw type parameters Object: the goto class CS/SE Individual Practical 13 / 24
  • 14.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Raw type parameters T extends Adapter doesn’t work CS/SE Individual Practical 14 / 24
  • 15.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Raw type parameters “?” — the wild card parameter CS/SE Individual Practical 15 / 24
  • 16.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Raw type parameters “Quick fix” would have worked here CS/SE Individual Practical 16 / 24
  • 17.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Raw type parameters Same result CS/SE Individual Practical 17 / 24
  • 18.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Working with the Java compiler Setting Java compiler preferences CS/SE Individual Practical 18 / 24
  • 19.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Working with the Java compiler Changing defaults CS/SE Individual Practical 19 / 24
  • 20.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Working with the Java compiler Potential programming problems CS/SE Individual Practical 20 / 24
  • 21.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Working with the Java compiler Tighter checking CS/SE Individual Practical 21 / 24
  • 22.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Working with the Java compiler Bug found CS/SE Individual Practical 22 / 24
  • 23.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Logging Don’t forget to add logging . . . CS/SE Individual Practical 23 / 24 .41.02.png
  • 24.
    Java problems Raw type parameters Working with the Java compiler Logging Static analysis Static analysis Deeper analysis (resource leaks . . . ) CS/SE Individual Practical 24 / 24