Selaa lähdekoodia

* catch JLRInvocationTargetException raised when using JLRMthod.invoke() to
call a procvar (includes virtual constructors and virtual class methods),
and raise its getCause() so that the original exception is propagated to
the caller

git-svn-id: branches/jvmbackend@19030 -

Jonas Maebe 14 vuotta sitten
vanhempi
commit
fdab7122dd
5 muutettua tiedostoa jossa 105 lisäystä ja 55 poistoa
  1. 10 0
      rtl/java/java_sys.inc
  2. 5 0
      rtl/java/java_sysh.inc
  3. 0 10
      rtl/java/jdk15.inc
  4. 0 5
      rtl/java/jdk15.pas
  5. 90 40
      rtl/java/jpvar.inc

+ 10 - 0
rtl/java/java_sys.inc

@@ -2139,6 +2139,16 @@
     constructor create(para1: JLThrowable); overload;
     constructor create(para1: JLThrowable); overload;
   end;
   end;
 
 
+  JLRInvocationTargetException = class external 'java.lang.reflect' name 'InvocationTargetException' (JLException)
+  strict protected
+    constructor create(); overload;
+  public
+    constructor create(para1: JLThrowable); overload;
+    constructor create(para1: JLThrowable; para2: JLString); overload;
+    function getTargetException(): JLThrowable; overload; virtual;
+    function getCause(): JLThrowable; overload; virtual;
+  end;
+
   JLStringBuffer = class sealed external 'java.lang' name 'StringBuffer' (JLAbstractStringBuilder, JISerializable, JLCharSequence)
   JLStringBuffer = class sealed external 'java.lang' name 'StringBuffer' (JLAbstractStringBuilder, JISerializable, JLCharSequence)
   public
   public
     constructor create(); overload;
     constructor create(); overload;

+ 5 - 0
rtl/java/java_sysh.inc

@@ -30,6 +30,11 @@ type
   Arr2JLRField = array of Arr1JLRField;
   Arr2JLRField = array of Arr1JLRField;
   Arr3JLRField = array of Arr2JLRField;
   Arr3JLRField = array of Arr2JLRField;
 
 
+  JLRInvocationTargetException = class;
+  Arr1JLRInvocationTargetException = array of JLRInvocationTargetException;
+  Arr2JLRInvocationTargetException = array of Arr1JLRInvocationTargetException;
+  Arr3JLRInvocationTargetException = array of Arr2JLRInvocationTargetException;
+
   JNBuffer = class;
   JNBuffer = class;
   Arr1JNBuffer = array of JNBuffer;
   Arr1JNBuffer = array of JNBuffer;
   Arr2JNBuffer = array of Arr1JNBuffer;
   Arr2JNBuffer = array of Arr1JNBuffer;

+ 0 - 10
rtl/java/jdk15.inc

@@ -15913,16 +15913,6 @@
     constructor create(para1: JLString); overload;
     constructor create(para1: JLString); overload;
   end;
   end;
 
 
-  JLRInvocationTargetException = class external 'java.lang.reflect' name 'InvocationTargetException' (JLException)
-  strict protected
-    constructor create(); overload;
-  public
-    constructor create(para1: JLThrowable); overload;
-    constructor create(para1: JLThrowable; para2: JLString); overload;
-    function getTargetException(): JLThrowable; overload; virtual;
-    function getCause(): JLThrowable; overload; virtual;
-  end;
-
   JNURISyntaxException = class external 'java.net' name 'URISyntaxException' (JLException)
   JNURISyntaxException = class external 'java.net' name 'URISyntaxException' (JLException)
   public
   public
     constructor create(para1: JLString; para2: JLString; para3: jint); overload;
     constructor create(para1: JLString; para2: JLString; para3: jint); overload;

+ 0 - 5
rtl/java/jdk15.pas

@@ -14440,11 +14440,6 @@ type
   Arr2JSRSSQLInputImpl = array of Arr1JSRSSQLInputImpl;
   Arr2JSRSSQLInputImpl = array of Arr1JSRSSQLInputImpl;
   Arr3JSRSSQLInputImpl = array of Arr2JSRSSQLInputImpl;
   Arr3JSRSSQLInputImpl = array of Arr2JSRSSQLInputImpl;
 
 
-  JLRInvocationTargetException = class;
-  Arr1JLRInvocationTargetException = array of JLRInvocationTargetException;
-  Arr2JLRInvocationTargetException = array of Arr1JLRInvocationTargetException;
-  Arr3JLRInvocationTargetException = array of Arr2JLRInvocationTargetException;
-
   OXSSAXParseException = class;
   OXSSAXParseException = class;
   Arr1OXSSAXParseException = array of OXSSAXParseException;
   Arr1OXSSAXParseException = array of OXSSAXParseException;
   Arr2OXSSAXParseException = array of Arr1OXSSAXParseException;
   Arr2OXSSAXParseException = array of Arr1OXSSAXParseException;

+ 90 - 40
rtl/java/jpvar.inc

@@ -100,91 +100,141 @@
         in a synchronised way. Doing it at construction time and in fpcDeepCopy/
         in a synchronised way. Doing it at construction time and in fpcDeepCopy/
         clone is not enough, because the method field can be manipulated
         clone is not enough, because the method field can be manipulated
         directly }
         directly }
-      if length(method.code.getParameterTypes)=length(args) then
-        method.code.invoke(method.data,args)
-      else
-        method.code.invoke(method.data,getClassProcArgs(args));
+      try
+        if length(method.code.getParameterTypes)=length(args) then
+          method.code.invoke(method.data,args)
+        else
+          method.code.invoke(method.data,getClassProcArgs(args));
+      except
+        on e: JLRInvocationTargetException do
+          raise e.getCause
+      end;
     end;
     end;
 
 
 
 
   function FpcBaseProcVarType.invokeBooleanFunc(const args: array of jlobject): jboolean;
   function FpcBaseProcVarType.invokeBooleanFunc(const args: array of jlobject): jboolean;
     begin
     begin
-      if length(method.code.getParameterTypes)=length(args) then
-        result:=JLBoolean(method.code.invoke(method.data,args)).booleanValue
-      else
-        result:=JLBoolean(method.code.invoke(method.data,getClassProcArgs(args))).booleanValue
+      try
+        if length(method.code.getParameterTypes)=length(args) then
+          result:=JLBoolean(method.code.invoke(method.data,args)).booleanValue
+        else
+          result:=JLBoolean(method.code.invoke(method.data,getClassProcArgs(args))).booleanValue
+      except
+        on e: JLRInvocationTargetException do
+          raise e.getCause
+      end;
     end;
     end;
 
 
 
 
   function FpcBaseProcVarType.invokeCharFunc(const args: array of jlobject): jchar;
   function FpcBaseProcVarType.invokeCharFunc(const args: array of jlobject): jchar;
     begin
     begin
-      if length(method.code.getParameterTypes)=length(args) then
-        result:=JLCharacter(method.code.invoke(method.data,args)).charValue
-      else
-        result:=JLCharacter(method.code.invoke(method.data,getClassProcArgs(args))).charValue;
+      try
+        if length(method.code.getParameterTypes)=length(args) then
+          result:=JLCharacter(method.code.invoke(method.data,args)).charValue
+        else
+          result:=JLCharacter(method.code.invoke(method.data,getClassProcArgs(args))).charValue;
+      except
+        on e: JLRInvocationTargetException do
+          raise e.getCause
+      end;
     end;
     end;
 
 
 
 
   function FpcBaseProcVarType.invokeByteFunc(const args: array of jlobject): jbyte;
   function FpcBaseProcVarType.invokeByteFunc(const args: array of jlobject): jbyte;
     begin
     begin
-      if length(method.code.getParameterTypes)=length(args) then
-        result:=JLByte(method.code.invoke(method.data,args)).byteValue
-      else
-        result:=JLByte(method.code.invoke(method.data,getClassProcArgs(args))).byteValue
+      try
+        if length(method.code.getParameterTypes)=length(args) then
+          result:=JLByte(method.code.invoke(method.data,args)).byteValue
+        else
+          result:=JLByte(method.code.invoke(method.data,getClassProcArgs(args))).byteValue
+      except
+        on e: JLRInvocationTargetException do
+          raise e.getCause
+      end;
     end;
     end;
 
 
 
 
   function FpcBaseProcVarType.invokeShortFunc(const args: array of jlobject): jshort;
   function FpcBaseProcVarType.invokeShortFunc(const args: array of jlobject): jshort;
     begin
     begin
-      if length(method.code.getParameterTypes)=length(args) then
-        result:=JLShort(method.code.invoke(method.data,args)).shortValue
-      else
-        result:=JLShort(method.code.invoke(method.data,getClassProcArgs(args))).shortValue
+      try
+        if length(method.code.getParameterTypes)=length(args) then
+          result:=JLShort(method.code.invoke(method.data,args)).shortValue
+        else
+          result:=JLShort(method.code.invoke(method.data,getClassProcArgs(args))).shortValue
+      except
+        on e: JLRInvocationTargetException do
+          raise e.getCause
+      end;
     end;
     end;
 
 
 
 
   function FpcBaseProcVarType.invokeIntFunc(const args: array of jlobject): jint;
   function FpcBaseProcVarType.invokeIntFunc(const args: array of jlobject): jint;
     begin
     begin
-      if length(method.code.getParameterTypes)=length(args) then
-        result:=JLInteger(method.code.invoke(method.data,args)).intValue
-      else
-        result:=JLInteger(method.code.invoke(method.data,getClassProcArgs(args))).intValue
+      try
+        if length(method.code.getParameterTypes)=length(args) then
+          result:=JLInteger(method.code.invoke(method.data,args)).intValue
+        else
+          result:=JLInteger(method.code.invoke(method.data,getClassProcArgs(args))).intValue
+      except
+        on e: JLRInvocationTargetException do
+          raise e.getCause
+      end;
     end;
     end;
 
 
 
 
   function FpcBaseProcVarType.invokeLongFunc(const args: array of jlobject): jlong;
   function FpcBaseProcVarType.invokeLongFunc(const args: array of jlobject): jlong;
     begin
     begin
-      if length(method.code.getParameterTypes)=length(args) then
-        result:=JLLong(method.code.invoke(method.data,args)).longValue
-      else
-        result:=JLLong(method.code.invoke(method.data,getClassProcArgs(args))).longValue;
+      try
+        if length(method.code.getParameterTypes)=length(args) then
+          result:=JLLong(method.code.invoke(method.data,args)).longValue
+        else
+          result:=JLLong(method.code.invoke(method.data,getClassProcArgs(args))).longValue;
+      except
+        on e: JLRInvocationTargetException do
+          raise e.getCause
+      end;
     end;
     end;
 
 
 
 
   function FpcBaseProcVarType.invokeSingleFunc(const args: array of jlobject): jfloat;
   function FpcBaseProcVarType.invokeSingleFunc(const args: array of jlobject): jfloat;
     begin
     begin
-      if length(method.code.getParameterTypes)=length(args) then
-        result:=JLFloat(method.code.invoke(method.data,args)).floatValue
-      else
-        result:=JLFloat(method.code.invoke(method.data,getClassProcArgs(args))).floatValue
+      try
+        if length(method.code.getParameterTypes)=length(args) then
+          result:=JLFloat(method.code.invoke(method.data,args)).floatValue
+        else
+          result:=JLFloat(method.code.invoke(method.data,getClassProcArgs(args))).floatValue
+      except
+        on e: JLRInvocationTargetException do
+          raise e.getCause
+      end;
     end;
     end;
 
 
 
 
   function FpcBaseProcVarType.invokeDoubleFunc(const args: array of jlobject): jdouble;
   function FpcBaseProcVarType.invokeDoubleFunc(const args: array of jlobject): jdouble;
     begin
     begin
-      if length(method.code.getParameterTypes)=length(args) then
-        result:=JLDouble(method.code.invoke(method.data,args)).doubleValue
-      else
-        result:=JLDouble(method.code.invoke(method.data,getClassProcArgs(args))).doubleValue
+      try
+        if length(method.code.getParameterTypes)=length(args) then
+          result:=JLDouble(method.code.invoke(method.data,args)).doubleValue
+        else
+          result:=JLDouble(method.code.invoke(method.data,getClassProcArgs(args))).doubleValue
+      except
+        on e: JLRInvocationTargetException do
+          raise e.getCause
+      end;
     end;
     end;
 
 
 
 
   function FpcBaseProcVarType.invokeObjectFunc(const args: array of jlobject): jlobject;
   function FpcBaseProcVarType.invokeObjectFunc(const args: array of jlobject): jlobject;
     begin
     begin
-      if length(method.code.getParameterTypes)=length(args) then
-        result:=method.code.invoke(method.data,args)
-      else
-        result:=method.code.invoke(method.data,getClassProcArgs(args))
+      try
+        if length(method.code.getParameterTypes)=length(args) then
+          result:=method.code.invoke(method.data,args)
+        else
+          result:=method.code.invoke(method.data,getClassProcArgs(args))
+      except
+        on e: JLRInvocationTargetException do
+          raise e.getCause
+      end;
     end;
     end;