Search code examples
javacastingcompilationdecompilertype-safety

Is this compilation or decompilation side effects?


Were running a server . A guy got fired. He deleted source code. We must decompile....: I noticed several weird stuff:

1) The variable declerations are also in the middle of the program at random spots 2) No type safety of HashMaps e.g.

HashMap<Integer , Boolean> s = new HashMap<Integer , Boolean>();

got turned into HashMap s = new HashMap(); the same thing happened to Lists and Collections generally. It also has some side effects that caused some exceptions ((Long) list.get(a_long).longValue()); The stuff added were the cast and the longValue call

3)I also noticed some trash coding

Did these things happen because I decompiled the program , or did these things happen due to the compiler or stupidity of ex-developer?


Solution

  • What you are observing is a result of type erasure and autoboxing. In Java generics, the generic types are enforced by the compiler, but the underlying implementation at the byte code level has no notion of the generic types (they are "erased"), which is why these have disappeared. Similarly, conversions between Integer and int or vice-versa (and similarly for other primitives) is done through "autoboxing" which is basically where the compiler is inserting these explicit calls to the conversion methods for you.