SF 1607878 Variant getJavaDateRef() failes -- programmer error

SF 1602188 stack overflow on toString() for object that can't be converted toJavaObject() -- toJavaObject did wrong thing when couldn't convert and couldn't convert basic types byRef() .  That has been fixed.
This commit is contained in:
clay_shooter
2006-12-03 14:53:49 +00:00
parent f3f83ea562
commit 5ac71b76b4
2 changed files with 184 additions and 40 deletions

View File

@@ -482,7 +482,7 @@ public class Variant extends JacobObject {
if (windowsDate == 0){ if (windowsDate == 0){
return null; return null;
} else { } else {
return DateUtilities.convertWindowsTimeToDate(getDate()); return DateUtilities.convertWindowsTimeToDate(windowsDate);
} }
} }
@@ -1320,7 +1320,10 @@ public class Variant extends JacobObject {
private native void changeVariantType(short in); private native void changeVariantType(short in);
/** /**
* cover for native method so we can cover it. * Cover for native method so we can cover it.
* <p>
* This cannot convert an object to a byRef.
* It can convert from byref to not byref
* @param in type to convert this variant too * @param in type to convert this variant too
* @return Variant returns this same object so folks can change when replacing calls * @return Variant returns this same object so folks can change when replacing calls
* toXXX() with changeType().getXXX() * toXXX() with changeType().getXXX()
@@ -1664,7 +1667,8 @@ public class Variant extends JacobObject {
* Convert a JACOB Variant value to a Java object * Convert a JACOB Variant value to a Java object
* (type conversions). * (type conversions).
* provided in Sourceforge feature request 959381. * provided in Sourceforge feature request 959381.
* * A fix was done to handle byRef bug report 1607878.
* <p>
* Unlike other toXXX() methods, it does not do a type conversion * Unlike other toXXX() methods, it does not do a type conversion
* except for special data types (it shouldn't do any!) * except for special data types (it shouldn't do any!)
* *
@@ -1677,7 +1681,7 @@ public class Variant extends JacobObject {
short type = this.getvt(); //variant type short type = this.getvt(); //variant type
if (type >= Variant.VariantArray) { //array returned? if ((type & Variant.VariantArray) == VariantArray) { //array returned?
SafeArray array = null; SafeArray array = null;
type = (short) (type - Variant.VariantArray); type = (short) (type - Variant.VariantArray);
array = this.toSafeArray(false); array = this.toSafeArray(false);
@@ -1689,58 +1693,84 @@ public class Variant extends JacobObject {
case Variant.VariantNull : //1 case Variant.VariantNull : //1
break; break;
case Variant.VariantShort : //2 case Variant.VariantShort : //2
result = new Short(this.getShort()); result = new Short(this.getShort());
break; break;
case Variant.VariantShort | Variant.VariantByref : //2
result = new Short(this.getShortRef());
break;
case Variant.VariantInt : //3 case Variant.VariantInt : //3
result = new Integer(this.getInt()); result = new Integer(this.getInt());
break; break;
case Variant.VariantInt | Variant.VariantByref: //3
result = new Integer(this.getIntRef());
break;
case Variant.VariantFloat : //4 case Variant.VariantFloat : //4
result = new Float(this.getFloat()); result = new Float(this.getFloat());
break; break;
case Variant.VariantFloat | Variant.VariantByref: //4
result = new Float(this.getFloatRef());
break;
case Variant.VariantDouble : //5 case Variant.VariantDouble : //5
result = new Double(this.getDouble()); result = new Double(this.getDouble());
break; break;
case Variant.VariantDouble | Variant.VariantByref: //5
result = new Double(this.getDoubleRef());
break;
case Variant.VariantCurrency : //6 case Variant.VariantCurrency : //6
result = new Long(this.getCurrency()); result = new Long(this.getCurrency());
break; break;
case Variant.VariantCurrency | Variant.VariantByref: //6
result = new Long(this.getCurrencyRef());
break;
case Variant.VariantDate : //7 case Variant.VariantDate : //7
result = this.getJavaDate(); result = this.getJavaDate();
break; break;
case Variant.VariantDate | Variant.VariantByref : //7
result = this.getJavaDateRef();
break;
case Variant.VariantString : //8 case Variant.VariantString : //8
result = this.getString(); result = this.getString();
break; break;
case Variant.VariantString | Variant.VariantByref: //8
result = this.getStringRef();
break;
case Variant.VariantDispatch : //9 case Variant.VariantDispatch : //9
result = this.getDispatchRef(); result = this.getDispatchRef();
break; break;
case Variant.VariantError : //10 case Variant.VariantError : //10
result = new NotImplementedException("toJavaObject() Not implemented for VariantError"); result = new NotImplementedException("toJavaObject() Not implemented for VariantError");
break; break;
case Variant.VariantBoolean : //11 case Variant.VariantBoolean : //11
result = new Boolean(this.getBoolean()); result = new Boolean(this.getBoolean());
break; break;
case Variant.VariantBoolean | Variant.VariantByref: //11
result = new Boolean(this.getBooleanRef());
break;
case Variant.VariantVariant : //12 case Variant.VariantVariant : //12
result = new NotImplementedException("toJavaObject() Not implemented for VariantVariant"); result = new NotImplementedException("toJavaObject() Not implemented for VariantVariant");
break; break;
case Variant.VariantObject : //13 case Variant.VariantObject : //13
result = new NotImplementedException("toJavaObject() Not implemented for VariantObject"); result = new NotImplementedException("toJavaObject() Not implemented for VariantObject");
break; break;
case Variant.VariantByte : //17 case Variant.VariantByte : //17
result = new Byte(this.getByte()); result = new Byte(this.getByte());
//result = new IllegalStateException("toJavaObject() Not implemented for VariantByte"); break;
break; case Variant.VariantByte | Variant.VariantByref: //17
result = new Byte(this.getByteRef());
break;
case Variant.VariantTypeMask : //4095 case Variant.VariantTypeMask : //4095
result = new NotImplementedException("toJavaObject() Not implemented for VariantTypeMask"); result = new NotImplementedException("toJavaObject() Not implemented for VariantTypeMask");
break; break;
case Variant.VariantArray : //8192 case Variant.VariantArray : //8192
result = new NotImplementedException("toJavaObject() Not implemented for VariantArray"); result = new NotImplementedException("toJavaObject() Not implemented for VariantArray");
break; break;
case Variant.VariantByref : //16384 case Variant.VariantByref : //16384
result = new NotImplementedException("toJavaObject() Not implemented for VariantByref"); result = new NotImplementedException("toJavaObject() Not implemented for VariantByref");
break; break;
default : default :
result = new NotImplementedException("Unknown return type: " + type); result = new NotImplementedException("Unknown return type: " + type);
result = this; // there was a "return result" here that caused defect 1602118 so it was removed
break; break;
}//switch (type) }//switch (type)
if (result instanceof JacobException) { if (result instanceof JacobException) {

View File

@@ -20,6 +20,8 @@ class VariantTest {
testJig.testSafeReleaseConstant(); testJig.testSafeReleaseConstant();
testJig.testSafeReleaseString(); testJig.testSafeReleaseString();
testJig.testObjectIsAConstant(); testJig.testObjectIsAConstant();
testJig.testSomeChangeVT();
testJig.testByRefToJavaObject();
System.out.println("Testing Complete"); System.out.println("Testing Complete");
} }
@@ -32,6 +34,118 @@ class VariantTest {
} }
/**
* This verifies that toJavaObject() works for all of the
* main data types when they exist as a byRef version.
* <p>
* It compares the toJavaObject() for a byref against the
* toJavaObject() for the regular.
*
*/
private void testByRefToJavaObject(){
Variant v = null;
Variant vByRef = null;
v = new Variant(new Float(53.3),false);
vByRef = new Variant(new Float(53.3),true);
if (!v.toJavaObject().equals(vByRef.toJavaObject())){
System.out.println(v.toString() + " could not make type "
+ v.getvt() +" and "+ vByRef.getvt()
+" java objects come out the same");
}
v = new Variant(new Double(53.3),false);
vByRef = new Variant(new Double(53.3),true);
if (!v.toJavaObject().equals(vByRef.toJavaObject())){
System.out.println(v.toString() + " could not make type "
+ v.getvt() +" and "+ vByRef.getvt()
+" java objects come out the same");
}
v = new Variant(new Boolean(true),false);
vByRef = new Variant(new Boolean(true),true);
if (!v.toJavaObject().equals(vByRef.toJavaObject())){
System.out.println(v.toString() + " could not make type "
+ v.getvt() +" and "+ vByRef.getvt()
+" java objects come out the same");
}
v = new Variant(new Integer(53),false);
vByRef = new Variant(new Integer(53),true);
if (!v.toJavaObject().equals(vByRef.toJavaObject())){
System.out.println(v.toString() + " could not make type "
+ v.getvt() +" and "+ vByRef.getvt()
+" java objects come out the same");
}
v = new Variant(new Short((short)53),false);
vByRef = new Variant(new Short((short)53),true);
if (!v.toJavaObject().equals(vByRef.toJavaObject())){
System.out.println(v.toString() + " could not make type "
+ v.getvt() +" and "+ vByRef.getvt()
+" java objects come out the same");
}
v = new Variant("53.33",false);
vByRef = new Variant("53.33",true);
if (!v.toJavaObject().equals(vByRef.toJavaObject())){
System.out.println(v.toString() + " could not make type "
+ v.getvt() +" and "+ vByRef.getvt()
+" java objects come out the same");
}
Date now = new Date();
v = new Variant(now,false);
vByRef = new Variant(now,true);
if (!v.toJavaObject().equals(vByRef.toJavaObject())){
System.out.println(v.toString() + " could not make type "
+ v.getvt() +" and "+ vByRef.getvt()
+" java objects come out the same");
}
// need to do currency also
}
/**
* see what happens when we conver to by ref
*
*/
private void testSomeChangeVT(){
Variant v;
// the code shows e shouldn't need to use a returned Variant but the test says we do
Variant vConverted;
v = new Variant(53.3);
short originalVT = v.getvt();
short modifier;
modifier = Variant.VariantShort;
vConverted = v.changeType(modifier);
if (vConverted.getvt() != modifier){
System.out.println("Failed to change Variant "+originalVT
+ " using mask "+modifier
+ " resulted in "+vConverted.getvt()
);
}
modifier = Variant.VariantString;
vConverted = v.changeType(modifier);
if (vConverted.getvt() != modifier){
System.out.println("Failed to change Variant "+originalVT
+ " using mask "+modifier
+ " resulted in "+vConverted.getvt()
);
}
// can't convert to byref!
modifier = Variant.VariantByref | Variant.VariantShort;
vConverted = v.changeType(modifier);
if (vConverted.getvt() == modifier){
System.out.println("Should not have been able to change Variant "+originalVT
+ " using mask "+modifier
+ " resulted in "+vConverted.getvt()
);
}
}
/** /**
* make sure variant with no backing store works. * make sure variant with no backing store works.
* *