/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * NullProxy is a java dynamic proxy that wraps an object referenced by it's * interface rather than it's concrete type. * * Copyright (C) 2003 R. Dale Asberry * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * R. Dale Asberry - initial implementation * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ package test; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.util.ArrayList; public class NullProxy implements InvocationHandler { private String cProxiedType = null; private NullPointerException cNpe = null; public NullProxy(String pType, NullPointerException pNpe) { cProxiedType = pType; cNpe = pNpe; } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { NullPointerException lNpe = new NullPointerException(); if(!"hashCode".equals(method.getName())) { StackTraceElement [] lStackTrace = lNpe.getStackTrace(); ArrayList lNewStackTraceElements = new ArrayList(); for(int i = 0; i < lStackTrace.length; i++) { //Filter out confusing aspect-related stack trace elements if ( !(lStackTrace[i].toString().indexOf("_aroundBody") > -1) && !(lStackTrace[i].toString().indexOf("NullProxy.invoke") > -1) && !(lStackTrace[i].toString().indexOf("$Proxy") > -1) ) { lNewStackTraceElements.add(lStackTrace[i]); } } StackTraceElement [] lNewStackTrace = new StackTraceElement [lNewStackTraceElements.size()]; for(int i = 0; i < lNewStackTraceElements.size(); i++) { lNewStackTrace[i] = (StackTraceElement)lNewStackTraceElements.get(i); } lNpe.setStackTrace(lNewStackTrace); lNpe.initCause(cNpe); throw lNpe; } return new Integer(this.hashCode()); } }