...
"Ideally, boxing a given primitive value p, would always yield an identical reference. In practice, this may not be feasible using existing implementation techniques. The rules above are a pragmatic compromise. The final clause above requires that certain common values always be boxed into indistinguishable objects. The implementation may cache these, lazily or eagerly."(From section 5.1.7 of JLS 3rd Ed_)_
To convince our idea, we can take an insight of the source code of Integer of JDK 1.6.0_10 from java SE:
Code Block |
---|
 private static class IntegerCache {  private IntegerCache(){}  static final Integer cache[] = new Integer[-(-128) + 127 + 1];  static {     for(int i = 0; i < cache.length; i++)   cache[i] = new Integer(i - 128);  }    } |
...
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
EXP05-J | medium | likely | high low | P9 | L2 |
Automated Detection
TODO
...
Chapter 5, Core Java⢠2 Volume I - Fundamentals, Seventh Edition By by Cay S. Horstmann, Gary Cornell
Publisher:Prentice Hall PTR;Pub Date:August 17, 2004.
Section 5.1.7, The Java⢠Language Specification,Third Edition by James Gosling, Bill Joy, Guy Steele, Gilad Bracha
Publisher:ADDISON-WESLEY;Pub Date:May 2005.