You are viewing a plain text version of this content. The canonical link for it is here.
Posted to kato-commits@incubator.apache.org by mo...@apache.org on 2009/12/04 13:31:15 UTC
svn commit: r887184 - in
/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model:
JClass.java JField.java JObject.java
Author: monteith
Date: Fri Dec 4 13:31:11 2009
New Revision: 887184
URL: http://svn.apache.org/viewvc?rev=887184&view=rev
Log:
Fix JavaField.get*() methods tests.
Modified:
incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JClass.java
incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JField.java
incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JObject.java
Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JClass.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JClass.java?rev=887184&r1=887183&r2=887184&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JClass.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JClass.java Fri Dec 4 13:31:11 2009
@@ -249,6 +249,5 @@
return f;
}
-
}
Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JField.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JField.java?rev=887184&r1=887183&r2=887184&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JField.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JField.java Fri Dec 4 13:31:11 2009
@@ -51,16 +51,30 @@
@Override
public Object get(JavaObject arg0) throws CorruptDataException,
MemoryAccessException {
- if (staticValue != null) {
+
+ if (staticField) {
return staticValue;
}
CLogger.logr.log(Level.FINEST," " + this.name + " " + this.index + " "
+ this.signature);
+
+ if(arg0 == null) {
+ throw new NullPointerException("Instance field passed null object.");
+ }
+
+ if(!(arg0 instanceof JObject)) {
+ throw new IllegalArgumentException("Non CJVMTI JavaObject implementation was passed.");
+ }
+
JObject job = (JObject) arg0;
-
+
+
+ if(!((JObject)job).isInstance(clazzid)) {
+ throw new IllegalArgumentException("Passed object incompatible with this fields' class.");
+ }
+
return job.getValue(id);
-
}
@Override
Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JObject.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JObject.java?rev=887184&r1=887183&r2=887184&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JObject.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JObject.java Fri Dec 4 13:31:11 2009
@@ -74,23 +74,43 @@
}
public double getDoubleValue(long id) {
- Double d = (Double) data.get(id); // First try from this object
+ Object obj = data.get(id);
+ if (obj instanceof Character) {
+ return ((Character) obj).charValue();
+ } else if(!(obj instanceof Number)) {
+ throw new IllegalArgumentException("Cannot retrieve double from field");
+ }
+ Number d = (Number) obj; // First try from this object
if (d == null && superClazzObject != null) { // Then follow through the hierarchy
return superClazzObject.getDoubleValue(id);
}
- return d;
+ return d.doubleValue();
}
public long getLongValue(long id) {
- Long d = (Long) data.get(id);
+ Object obj = data.get(id);
+ if (obj instanceof Character) {
+ return ((Character) obj).charValue();
+ } else if (obj instanceof Double) {
+ throw new IllegalArgumentException();
+ } else if (obj instanceof Float) {
+ throw new IllegalArgumentException();
+ } else if(!(obj instanceof Number)) {
+ throw new IllegalArgumentException("Cannot retrieve long from field.");
+ }
+ Number d = (Number) obj;
if (d == null && superClazzObject != null) {
return superClazzObject.getLongValue(id);
}
- return d;
+ return d.longValue();
}
public char getCharValue(long id) {
- Character d = (Character) data.get(id);
+ Object obj = data.get(id);
+ if (!(obj instanceof Character)) {
+ throw new IllegalArgumentException("Can only retrieve get character from a character.");
+ }
+ Character d = (Character) obj;
if (d == null && superClazzObject != null) {
return superClazzObject.getCharValue(id);
}
@@ -99,7 +119,11 @@
}
public boolean getBooleanValue(long id) {
- Boolean d = (Boolean) data.get(id);
+ Object obj = data.get(id);
+ if(!(obj instanceof Boolean)) {
+ throw new IllegalArgumentException("Cannot retrieve non-boolean values.");
+ }
+ Boolean d = (Boolean) obj;
if (d == null && superClazzObject != null) {
return superClazzObject.getBooleanValue(id);
}
@@ -107,35 +131,85 @@
}
public byte getByteValue(long id) {
- Byte d = (Byte) data.get(id);
+ Object obj = data.get(id);
+ if (obj instanceof Double) {
+ throw new IllegalArgumentException("Canot convert double to byte.");
+ } else if (obj instanceof Float) {
+ throw new IllegalArgumentException("Canot convert float to byte");
+ } else if (obj instanceof Long) {
+ throw new IllegalArgumentException("Canot convert double to byte.");
+ } else if (obj instanceof Integer) {
+ throw new IllegalArgumentException("Canot convert double to int.");
+ } else if (obj instanceof Short) {
+ throw new IllegalArgumentException("Canot convert short to int.");
+ } else if (obj instanceof Character) {
+ throw new IllegalArgumentException("Canot convert character to byte.");
+ } else if(!(obj instanceof Number)) {
+ throw new IllegalArgumentException("Cannot retrieve byte from field");
+ }
+ Number d = (Number) obj;
if (d == null && superClazzObject != null) {
return superClazzObject.getByteValue(id);
}
- return d;
+ return d.byteValue();
}
public float getFloatValue(long id) {
- Float d = (Float) data.get(id);
+ Object obj = data.get(id);
+ if (obj instanceof Double) {
+ throw new IllegalArgumentException("Cannot convert double to float.");
+ } else if (obj instanceof Character) {
+ return ((Character) obj).charValue();
+ } else if(!(obj instanceof Number)) {
+ throw new IllegalArgumentException("Cannot retrieve float from field");
+ }
+ Number d = (Number) obj;
if (d == null && superClazzObject != null) {
return superClazzObject.getFloatValue(id);
}
- return d;
+ return d.floatValue();
}
public int getIntValue(long id) {
- Integer d = (Integer) data.get(id);
+ Object obj = data.get(id);
+ if (obj instanceof Double) {
+ throw new IllegalArgumentException("Cannot convert double to int.");
+ } else if (obj instanceof Float) {
+ throw new IllegalArgumentException("Cannot convert float to int.");
+ } else if (obj instanceof Long) {
+ throw new IllegalArgumentException("Cannot convert long to int.");
+ } else if (obj instanceof Character) {
+ return ((Character) obj).charValue();
+ } else if(!(obj instanceof Number)) {
+ throw new IllegalArgumentException("Cannot retrieve int from field");
+ }
+ Number d = (Number) obj;
if (d == null && superClazzObject != null) {
return superClazzObject.getIntValue(id);
}
- return d;
+ return d.intValue();
}
public short getShortValue(long id) {
- Short d = (Short) data.get(id);
+ Object obj = data.get(id);
+ if (obj instanceof Double) {
+ throw new IllegalArgumentException("Cannot convert double to short.");
+ } else if (obj instanceof Float) {
+ throw new IllegalArgumentException("Cannot convert float to short.");
+ } else if (obj instanceof Long) {
+ throw new IllegalArgumentException("Canot convert long to short.");
+ } else if (obj instanceof Integer) {
+ throw new IllegalArgumentException("Canot convert int to short");
+ } else if (obj instanceof Character) {
+ throw new IllegalArgumentException("Canot convert char to short");
+ } else if(!(obj instanceof Number)) {
+ throw new IllegalArgumentException("Cannot retrieve short from field");
+ }
+ Number d = (Number) obj;
if (d == null && superClazzObject != null) {
return superClazzObject.getShortValue(id);
}
- return d;
+ return d.shortValue();
}
public String getStringValue(long id) {
@@ -363,4 +437,22 @@
return false;
}
+
+ /**
+ * Checks if an instance of this object would
+ * be compatible with the passed class.
+ *
+ *
+ * @param type Class to check compatiblity with.
+ * @return true if instance of passed clazz
+ */
+ public boolean isInstance(JClass type) {
+ if (clazz.equals(type)) {
+ return true;
+ } else if (superClazzObject != null) {
+ return superClazzObject.isInstance(type);
+ } else {
+ return false;
+ }
+ }
}
\ No newline at end of file