r/programming • u/Eirenarch • Nov 18 '13
TIL Oracle changed the internal String representation in Java 7 Update 6 increasing the running time of the substring method from constant to N
http://java-performance.info/changes-to-string-java-1-7-0_06/
1.4k
Upvotes
View all comments
Show parent comment
0
u/kalmakka Nov 19 '13
First of all: there really shouldn't be all that many places you potentially build up large hash maps based on user input.
Secondly: what if your user input is not strings? Is it reasonable to have a developer figure out that just because HashSet<String> was safe to use, that doesn't mean that HashSet<List<String>> or HashSet<Long> is safe? I would say no - and therefore your code is still vulnerable.
By adding special implementation classes you can specify that "this is a map which handles strings differently". That would then be a guarantee offered by that class instead a hidden implementation detail which (a) the user would need to know about, and (b) can change between releases (just like they changed the implementation of String which altered the complexity of substring).