-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ceki Gulcu <ceki@qos.ch>
- Loading branch information
Showing
6 changed files
with
171 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/test/java/org/apache/log4j/helpers/VersionUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.apache.log4j.helpers; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class VersionUtilTest { | ||
|
||
@Test | ||
public void smoke() { | ||
assertEquals(4, VersionUtil.getJavaMajorVersion("1.4.xx")); | ||
assertEquals(5, VersionUtil.getJavaMajorVersion("1.5")); | ||
assertEquals(5, VersionUtil.getJavaMajorVersion("1.5.xx")); | ||
assertEquals(5, VersionUtil.getJavaMajorVersion("1.5AA")); | ||
assertEquals(7, VersionUtil.getJavaMajorVersion("1.7.0_80-b15")); | ||
assertEquals(8, VersionUtil.getJavaMajorVersion("1.8.0_311")); | ||
assertEquals(9, VersionUtil.getJavaMajorVersion("9EA")); | ||
assertEquals(9, VersionUtil.getJavaMajorVersion("9.0.1")); | ||
assertEquals(18, VersionUtil.getJavaMajorVersion("18.3+xx")); | ||
assertEquals(19, VersionUtil.getJavaMajorVersion("19")); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package org.apache.log4j.net; | ||
|
||
|
||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.lang.reflect.Field; | ||
import java.util.HashMap; | ||
import java.util.Hashtable; | ||
|
||
@Ignore | ||
public class HashmapDOSTest { | ||
|
||
Hashtable<Object, Object> ht = new Hashtable<Object, Object>(); | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
ObjectOutputStream oos; | ||
|
||
ObjectInputStream ois; | ||
int maxHashMapCapacity = getMaxHashMapCapacityValue(); | ||
|
||
@Before | ||
public void beforeEach() throws IOException { | ||
oos = new ObjectOutputStream(baos); | ||
} | ||
@Test | ||
public void smokeHashMap() throws Exception { | ||
HashMap<Object, Object> ht = createDeepMap(null, 10); | ||
setSizeUsingReflection(ht, maxHashMapCapacity); | ||
oos.writeObject(ht); | ||
oos.flush(); | ||
oos.close(); | ||
|
||
byte[] byteArray = baos.toByteArray(); | ||
|
||
System.out.println("byteArray,length="+byteArray.length); | ||
|
||
|
||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); | ||
ois = new ObjectInputStream(bais); | ||
|
||
Object o = ois.readObject(); | ||
|
||
|
||
} | ||
@Test | ||
public void smokeHashtable() throws Exception { | ||
Hashtable ht = new Hashtable(); | ||
ht.put("1", "1"); | ||
oos.writeObject(ht); | ||
oos.flush(); | ||
oos.close(); | ||
|
||
byte[] byteArray = baos.toByteArray(); | ||
|
||
System.out.println("byteArray,length="+byteArray.length); | ||
|
||
|
||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); | ||
ois = new ObjectInputStream(bais); | ||
|
||
Hashtable htback = (Hashtable) ois.readObject(); | ||
|
||
System.out.println(htback.get("1")); | ||
|
||
} | ||
|
||
private static void setSizeUsingReflection(HashMap map, int size) throws Exception { | ||
Field sizeField = HashMap.class.getDeclaredField("size"); | ||
sizeField.setAccessible(true); | ||
|
||
while (map != null) { | ||
sizeField.set(map, size); | ||
map = (HashMap) map.keySet().iterator().next(); | ||
} | ||
} | ||
|
||
static int getMaxHashMapCapacityValue() { | ||
Field maxHashMapCapacityField = null; | ||
try { | ||
maxHashMapCapacityField = HashMap.class.getDeclaredField("MAXIMUM_CAPACITY"); | ||
maxHashMapCapacityField.setAccessible(true); | ||
|
||
int maxHashMapCapacity = maxHashMapCapacityField.getInt(null); | ||
return maxHashMapCapacity; | ||
} catch (NoSuchFieldException e) { | ||
throw new RuntimeException("Unable to obtain field HashMap.MAXIMUM_CAPACITY", e); | ||
} catch (IllegalAccessException e) { | ||
throw new RuntimeException("Unable to read HashMap.MAXIMUM_CAPACITY", e); | ||
} | ||
} | ||
|
||
|
||
private static HashMap createDeepMap(HashMap child, int depth) { | ||
if (child == null) { | ||
child = new HashMap(); | ||
// add one last element so that buffer is flushed | ||
child.put(null, null); | ||
} | ||
|
||
if (depth <= 1) { | ||
return child; | ||
} | ||
|
||
HashMap parent = new HashMap(); | ||
parent.put(child, null); | ||
|
||
return createDeepMap(parent, depth - 1); | ||
} | ||
|
||
} |
Not in commit, jaadoc -> javadoc