From ed9ef5c8272e1f3e9ec5f75a60f369c90fc63a44 Mon Sep 17 00:00:00 2001 From: clay_shooter Date: Sun, 23 Apr 2006 21:01:55 +0000 Subject: [PATCH] Another round of changes for Sourceforge bug 147484. --- src/com/jacob/com/ROT.java | 3 ++- src/com/jacob/com/Variant.java | 36 ++++++++++++------------- unittest/com/jacob/com/VariantTest.java | 6 +++-- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/com/jacob/com/ROT.java b/src/com/jacob/com/ROT.java index a2f137c..63afe83 100644 --- a/src/com/jacob/com/ROT.java +++ b/src/com/jacob/com/ROT.java @@ -131,7 +131,8 @@ public abstract class ROT { // which causes a concurrent modification exception in HashMap JacobObject.debug("ROT: removing "+o.getClass().getName()); } else { - JacobObject.debug("ROT: removing "+o+"->"+o.getClass().getName()); + // Variant toString() is probably always bad in here + JacobObject.debug("ROT: removing "+o.hashCode()+"->"+o.getClass().getName()); } } o.safeRelease(); diff --git a/src/com/jacob/com/Variant.java b/src/com/jacob/com/Variant.java index 96ea177..172ef79 100644 --- a/src/com/jacob/com/Variant.java +++ b/src/com/jacob/com/Variant.java @@ -20,8 +20,6 @@ package com.jacob.com; import java.util.Date; -import java.util.HashMap; -import java.util.Map; /** * The multi-format data type used for all call backs and most communications @@ -35,11 +33,6 @@ import java.util.Map; public class Variant extends JacobObject { /** - * holds the list Variants that should never be freed - */ - private static Map VARIANTS_THAT_ARE_CONSTANTS = new HashMap(); - - /** * Use this constant for optional parameters */ public final static com.jacob.com.Variant DEFAULT; @@ -71,16 +64,6 @@ public class Variant extends JacobObject { VT_MISSING = vtMissing; } - /* - * adds all the constants to the list of those that should not be released - */ - static { - VARIANTS_THAT_ARE_CONSTANTS.put(VT_TRUE,VT_TRUE); - VARIANTS_THAT_ARE_CONSTANTS.put(VT_MISSING,VT_MISSING); - VARIANTS_THAT_ARE_CONSTANTS.put(VT_FALSE,VT_FALSE); - VARIANTS_THAT_ARE_CONSTANTS.put(DEFAULT,DEFAULT); - } - /** * Pointer to MS struct. */ @@ -825,6 +808,23 @@ public class Variant extends JacobObject { safeRelease(); } + /** + * returns true if the passed in Variant is a constant that should not be freed + * @param pVariant + * @return + */ + private boolean objectIsAConstant(Variant pVariant){ + if (pVariant == VT_FALSE || + pVariant == VT_TRUE || + pVariant == VT_MISSING || + pVariant == DEFAULT){ + return true; + } else { + return false; + } + + } + /** * This will release the "C" memory for the Variant * unless this Variant is one of the constants in which case @@ -844,7 +844,7 @@ public class Variant extends JacobObject { // finalized. this is not a big deal at all. // another way around this would be to create the constants // in their own thread so that they would never be released - if (!Variant.VARIANTS_THAT_ARE_CONSTANTS.containsValue(this)){ + if (!objectIsAConstant(this)){ super.safeRelease(); if (m_pVariant != 0) { release(); diff --git a/unittest/com/jacob/com/VariantTest.java b/unittest/com/jacob/com/VariantTest.java index 6b7d211..dfb6fda 100644 --- a/unittest/com/jacob/com/VariantTest.java +++ b/unittest/com/jacob/com/VariantTest.java @@ -38,7 +38,7 @@ class VariantTest { System.out.println("Variant value ("+v.getBoolean()+") " +"has survived SafeRelease()"); } - for ( int i = 0 ; i < 20000; i ++){ + for ( int i = 0 ; i < 10; i ++){ new Variant ("xxx"+i); new Variant(i); new Variant ("yyy"+i); @@ -61,12 +61,14 @@ class VariantTest { } else { System.out.println("VT_TRUE survived SafeRelease()"); } - for ( int i = 0 ; i < 20000; i ++){ + + for ( int i = 0 ; i < 10; i ++){ new Variant ("xxx"+i); new Variant(i); new Variant ("yyy"+i); } ComThread.Release(); + if (Variant.VT_TRUE.getBoolean() != true){ System.out.println("VT_TRUE has been broken by ComThread.Release()"); } else {