Refactoring release without testing over 200,000 lines of codebase After reading this article, I wondered if Java could do the same with class files.
As for the background of my research, I myself handle Java at work. This is because I wanted to refactor, but I wanted to reduce the man-hours as much as possible.
We will compare the hash value (SHA1) of the class file compiled with various changes based on the standard source code.
I used the certutil -hashfile
command to get the hash value.
Main.java
import java.util.Arrays;
import java.util.List;
public class Main {
/**
* test
*/
public static void test() {
System.out.println("test");
}
/**
* main
* @param args
*/
public static void main(String[] args) {
List<String> list = Arrays.asList("a", "b", "c");
System.out.println(list);
System.out.println("main");
test();
}
}
Hash value (SHA1): b38492ff5641fa0f074a82ca5f397c7ba7f3575d
The hash value of the Main.class file compiled from Main.java is as above. Compare this with the differences between the files after various changes.
Since the survey content is long, I will write from the results and conclusions.
--Add code --Add a comment (new line) --Add a blank line
--Change import order --Add a comment (existing line) --Change indent --Change grouping brackets
** There was no difference in the hash value (SHA1) of the class file ** Regarding the change, it seems that you can say "OK without testing" by comparing the difference of the class file. In particular, changing the indent tends to cause a large amount of difference in the source code, so I thought it would be nice if I could say "Compare class files and there is no difference, so it's OK".
Main.java
import java.util.Arrays;
import java.util.List;
public class Main {
/**
* test
*/
public static void test() {
System.out.println("test"); System.out.println("test2");
}
/**
* main
* @param args
*/
public static void main(String[] args) {
List<String> list = Arrays.asList("a", "b", "c");
System.out.println(list);
System.out.println("main");
test();
}
}
Hash value (SHA1): 2356a12ac1ca0147356c1eb9824bdacf94e5eaac
Main.java
import java.util.List;
import java.util.Arrays;
public class Main {
/**
* test
*/
public static void test() {
System.out.println("test");
}
/**
* main
* @param args
*/
public static void main(String[] args) {
List<String> list = Arrays.asList("a", "b", "c");
System.out.println(list);
System.out.println("main");
test();
}
}
Hash value (SHA1): b38492ff5641fa0f074a82ca5f397c7ba7f3575d
Main.java
import java.util.Arrays;
import java.util.List;
public class Main {
/**
* test
*/
public static void test() {
System.out.println("test");
}
/**
* main addcomment
* @param args
*/
public static void main(String[] args) {
List<String> list = Arrays.asList("a", "b", "c");
System.out.println(list);
System.out.println("main");
test();
}
}
Hash value (SHA1): b38492ff5641fa0f074a82ca5f397c7ba7f3575d
Main.java
import java.util.Arrays;
import java.util.List;
public class Main {
/**
* test
*/
public static void test() {
System.out.println("test");
}
/**
* main
* add comment
* @param args
*/
public static void main(String[] args) {
List<String> list = Arrays.asList("a", "b", "c");
System.out.println(list);
System.out.println("main");
test();
}
}
Hash value (SHA1): ʻa05020054dd7c85ef01c20bc9d1f0cc45c46d1e1`
Main.java
import java.util.Arrays;
import java.util.List;
public class Main {
/**
* test
*/
public static void test() {
System.out.println("test");
}
/**
* main
* @param args
*/
public static void main(String[] args) {
List<String> list = Arrays.asList("a", "b", "c");
System.out.println(list);
System.out.println("main");
test();
}
}
Hash value (SHA1): ʻa05020054dd7c85ef01c20bc9d1f0cc45c46d1e1`
Main.java
import java.util.Arrays;
import java.util.List;
public class Main {
/**
* test
*/
public static void test() {
System.out.println("test");
}
/**
* main
* @param args
*/
public static void main(String[] args) {
List<String> list = Arrays.asList("a", "b", "c");
System.out.println(list);
System.out.println("main");
test();
}
}
Hash value (SHA1): b38492ff5641fa0f074a82ca5f397c7ba7f3575d
Main.java
import java.util.Arrays;
import java.util.List;
public class Main {
/**
* test
*/
public static void test() {
System.out.println("test");
}
/**
* main
* @param args
*/
public static void main(String[] args) {
List<String> list = Arrays.asList("a", "b", "c");
System.out.println((list));
System.out.println("main");
test();
}
}
Hash value (SHA1): b38492ff5641fa0f074a82ca5f397c7ba7f3575d
Recommended Posts