DO NOT REPLY [Bug 18031] - ConstantPoolGen.lookupClass(String) finds LAST entry rather than first
| Newsgroups | gmane.comp.jakarta.bcel.devel |
|---|---|
| Message-ID | <[email protected]> |
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18031>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE. http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18031 ConstantPoolGen.lookupClass(String) finds LAST entry rather than first ------- Additional Comments From [email protected] 2003-03-23 20:02 ------- The fix is quite simple. Basically, the class_table is stored in a HashMap. HashMaps assume that there is only one entry per key, which is not the case in these bizarre obfuscated classes. The solution is to check to see if the key exists already before put'ing another one. This explains why BCEL's ConstantPoolGen.lookupClass(String) was always finding the LAST case, rather than the first. The fix is: original line 118: class_table.put(u8Bytes, new Index(i)); suggested replacement: String u8Bytes = u8.getBytes(); if (!class_table.containsKey(u8Bytes)) { class_table.put(u8Bytes, new Index(i)); } Note that this problem occurs with ALL of the HashMaps that are used to store non-trivial types in the ConstantPoolGen class. This fix should be applied to all of those cases as well.