From 73da1fdb893118d67777a2e8962965d2336ca6e2 Mon Sep 17 00:00:00 2001 From: slaws Date: Thu, 22 Mar 2012 15:53:41 +0000 Subject: TUSCANY-4034 - plug a few more potential memory leaks git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1303855 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/interfacedef/java/jaxws/BaseBeanGenerator.java | 5 +++-- .../sca/interfacedef/java/jaxws/FaultBeanGenerator.java | 9 +++++++-- .../interfacedef/java/jaxws/WrapperBeanGenerator.java | 17 +++++++++++++---- 3 files changed, 23 insertions(+), 8 deletions(-) (limited to 'sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org') diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java index ca39ec0e62..923d13cd5e 100644 --- a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java +++ b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java @@ -20,6 +20,7 @@ package org.apache.tuscany.sca.interfacedef.java.jaxws; import java.lang.annotation.Annotation; +import java.lang.ref.WeakReference; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -119,8 +120,8 @@ public abstract class BaseBeanGenerator implements Opcodes { JAVA_KEYWORDS.put("enum", "_enum"); } - protected static final Map> generatedClasses = - Collections.synchronizedMap(new WeakHashMap>()); + protected static final Map>> generatedClasses = + Collections.synchronizedMap(new WeakHashMap>>()); protected XMLAdapterExtensionPoint xmlAdapters; diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java index 2e82428f7e..28fd2afe73 100644 --- a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java +++ b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java @@ -23,6 +23,7 @@ import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; +import java.lang.ref.WeakReference; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -108,7 +109,11 @@ public class FaultBeanGenerator extends BaseBeanGenerator { public Class generate(Class exceptionClass, GeneratedClassLoader cl, Operation operation) { synchronized (exceptionClass) { QName element = getElementName(exceptionClass, operation); - Class faultBeanClass = generatedClasses.get(element); + WeakReference> wr = generatedClasses.get(element); + Class faultBeanClass = null; + if (wr != null){ + faultBeanClass = wr.get(); + } if (faultBeanClass == null) { // TUSCANY-3283 - all generated classes (including exception) should go in the namespace @@ -122,7 +127,7 @@ public class FaultBeanGenerator extends BaseBeanGenerator { String classSignature = "L" + classDescriptor + ";"; faultBeanClass = generate(classDescriptor, classSignature, namespace, name, getProperties(exceptionClass), cl); - generatedClasses.put(element, faultBeanClass); + generatedClasses.put(element, new WeakReference>(faultBeanClass)); } return faultBeanClass; } diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java index 42151464a4..ab7036c0ce 100644 --- a/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java +++ b/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java @@ -20,6 +20,7 @@ package org.apache.tuscany.sca.interfacedef.java.jaxws; import java.lang.annotation.Annotation; +import java.lang.ref.WeakReference; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -64,7 +65,11 @@ public class WrapperBeanGenerator extends BaseBeanGenerator { GeneratedClassLoader cl) { synchronized (m.getDeclaringClass()) { MethodKey key = new MethodKey(m, true); - Class wrapperClass = generatedClasses.get(key); + WeakReference> wr = generatedClasses.get(key); + Class wrapperClass = null; + if (wr != null){ + wrapperClass = wr.get(); + } if (wrapperClass == null) { String wrapperClassDescriptor = wrapperClassName.replace('.', '/'); String wrapperClassSignature = "L" + wrapperClassDescriptor + ";"; @@ -110,7 +115,7 @@ public class WrapperBeanGenerator extends BaseBeanGenerator { wrapperClass = generate(wrapperClassDescriptor, wrapperClassSignature, wrapperNamespace, wrapperName, properties .toArray(new BeanProperty[properties.size()]), cl); - generatedClasses.put(key, wrapperClass); + generatedClasses.put(key, new WeakReference>(wrapperClass)); } return wrapperClass; @@ -134,7 +139,11 @@ public class WrapperBeanGenerator extends BaseBeanGenerator { GeneratedClassLoader cl) { synchronized (m.getDeclaringClass()) { MethodKey key = new MethodKey(m, false); - Class wrapperClass = generatedClasses.get(key); + WeakReference> wr = generatedClasses.get(key); + Class wrapperClass = null; + if (wr != null){ + wrapperClass = wr.get(); + } if (wrapperClass == null) { String wrapperClassDescriptor = wrapperClassName.replace('.', '/'); String wrapperClassSignature = "L" + wrapperClassDescriptor + ";"; @@ -212,7 +221,7 @@ public class WrapperBeanGenerator extends BaseBeanGenerator { wrapperClass = generate(wrapperClassDescriptor, wrapperClassSignature, wrapperNamespace, wrapperName, properties .toArray(new BeanProperty[properties.size()]), cl); - generatedClasses.put(key, wrapperClass); + generatedClasses.put(key, new WeakReference>(wrapperClass)); } return wrapperClass; -- cgit v1.2.3