Skip to content

Commit

Permalink
I still need to update the surefire plugin to set -Djdk.map.althashin…
Browse files Browse the repository at this point in the history
…g.threshold=10
  • Loading branch information
MammatusPlatypus committed May 14, 2014
1 parent 3742f88 commit fa4c649
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/main/java/org/boon/collections/LazyMap.java
Expand Up @@ -28,6 +28,7 @@

package org.boon.collections;

import org.boon.core.Sys;
import org.boon.primitive.Arry;
import org.boon.Maps;

Expand Down Expand Up @@ -124,7 +125,14 @@ public Object get( Object key ) {

private void buildIfNeeded() {
if ( map == null ) {
map = new LinkedHashMap<>( size, 0.01f );

/** added to avoid hash collision attack. */
if (Sys.is1_7OrLater() && System.getProperty("jdk.map.althashing.threshold") != null) {
map = new LinkedHashMap<>( size, 0.01f );
} else {
map = new TreeMap<>();
}

for ( int index = 0; index < size; index++ ) {
map.put( keys[ index ], values[ index ] );
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/boon/core/value/LazyValueMap.java
Expand Up @@ -28,6 +28,7 @@

package org.boon.core.value;

import org.boon.core.Sys;
import org.boon.core.Value;
import org.boon.primitive.Arry;

Expand Down Expand Up @@ -214,7 +215,14 @@ public Set<Entry<String, Object>> entrySet() {

private final void buildMap() {

map = new HashMap<>( items.length );

/** added to avoid hash collision attack. */
if (Sys.is1_7OrLater() && System.getProperty("jdk.map.althashing.threshold") != null) {
map = new HashMap<>( items.length );
} else {
map = new TreeMap<>();
}


for ( Entry<String, Value> miv : items ) {
if ( miv == null ) {
Expand Down
13 changes: 12 additions & 1 deletion src/test/java/com/examples/EvilJsonParse.java
Expand Up @@ -30,6 +30,9 @@
import org.boon.IO;
import org.boon.json.JsonParserAndMapper;
import org.boon.json.JsonParserFactory;

import java.util.Map;

import static org.boon.Boon.puts;

/**
Expand All @@ -41,11 +44,19 @@ public static void main (String... args) {
long start;
long stop;
long time;


final String json = IO.read("/Users/Richard/dos_100000.json"); //talking IO time out of the equation
final JsonParserAndMapper mapper = new JsonParserFactory().create();

start = System.nanoTime();
Employee employee = mapper.parse(Employee.class, json);

final Map<String,Object> map = mapper.parseMap(json);

map.size();



stop = System.nanoTime();
time = (stop - start) / 1_000_000; //milli-seconds
puts ("time", time, "ms");
Expand Down

0 comments on commit fa4c649

Please sign in to comment.