You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2017/09/18 18:45:34 UTC

svn commit: r1808758 - in /uima/uv3/uimaj-v3/trunk/uimaj-core/src/main: java/org/apache/uima/ java/org/apache/uima/cas/impl/ resources/org/apache/uima/

Author: schor
Date: Mon Sep 18 18:45:34 2017
New Revision: 1808758

URL: http://svn.apache.org/viewvc?rev=1808758&view=rev
Log:
[UIMA-5573] add checks for inconsistent JCas / Type configurations

Modified:
    uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/UIMA_IllegalStateException.java
    uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSClassRegistry.java
    uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java
    uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties

Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/UIMA_IllegalStateException.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/UIMA_IllegalStateException.java?rev=1808758&r1=1808757&r2=1808758&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/UIMA_IllegalStateException.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/UIMA_IllegalStateException.java Mon Sep 18 18:45:34 2017
@@ -81,10 +81,11 @@ public class UIMA_IllegalStateException
    */
   public static final String CANNOT_SET_CAS_MANAGER = "cannot_set_cas_manager";
   
-  /**
-   * Cannot do feature accessing for JCas class {0}, because it is not associated with a committed UIMA Type, either because the type doesn''t exist, or hasn''t been committed.
-   */
+  /** Cannot do feature accessing for JCas class {0}, because it is not associated with a committed UIMA Type, either because the type doesn''t exist, or hasn''t been committed.*/
   public static final String JCAS_NO_TYPE = "JCAS_NO_TYPE";
+  
+  /** Loaded JCas Type {0} has feature {1} with two different type systems having different offsets; this is not supported. */
+  public static final String JCAS_INCOMPATIBLE_TYPE_SYSTEMS = "JCAS_INCOMPATIBLE_TYPE_SYSTEMS";
 
   /**
    * Creates a new exception with a null message.

Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSClassRegistry.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSClassRegistry.java?rev=1808758&r1=1808757&r2=1808758&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSClassRegistry.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSClassRegistry.java Mon Sep 18 18:45:34 2017
@@ -43,6 +43,7 @@ import java.util.Map.Entry;
 
 import org.apache.uima.UIMAFramework;
 import org.apache.uima.UIMARuntimeException;
+import org.apache.uima.UIMA_IllegalStateException;
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.CASException;
 import org.apache.uima.cas.CASRuntimeException;
@@ -467,12 +468,28 @@ public abstract class FSClassRegistry {
       ArrayList<Entry<String, MutableCallSite>> callsites = callSites_all_JCasClasses.get(clazz);
       if (null != callsites) {
         for (Entry<String, MutableCallSite> e : callsites) {
-          e.getValue().setTarget(getConstantIntMethodHandle(TypeSystemImpl.getAdjustedFeatureOffset(e.getKey())));
-          callSites_toSync.add(e.getValue());
+          final int index = TypeSystemImpl.getAdjustedFeatureOffset(e.getKey());
+          final int prev = (int) e.getValue().getTarget().invokeExact();
+          
+          if (prev == -1) {
+            MethodHandle mh_constant = getConstantIntMethodHandle(index);
+
+            e.getValue().setTarget(mh_constant);
+            callSites_toSync.add(e.getValue());
+          } else if (prev != index) {
+            throw new UIMA_IllegalStateException(UIMA_IllegalStateException.JCAS_INCOMPATIBLE_TYPE_SYSTEMS,
+                new Object[] {ti.getName(), e.getKey()});
+          }
+
         }
       }
     } catch (ClassNotFoundException e) {
-      // This is normal, if there is no JCas for this class
+      // Class not found is normal, if there is no JCas for this class
+    } catch (Throwable e1) {
+      if (e1 instanceof UIMA_IllegalStateException) {
+        throw (UIMA_IllegalStateException) e1;
+      }
+      throw Misc.internalError();  // from invokeExact
     } finally {
       TypeSystemImpl.typeBeingLoadedThreadLocal.set(null);
     }

Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java?rev=1808758&r1=1808757&r2=1808758&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java Mon Sep 18 18:45:34 2017
@@ -33,6 +33,8 @@ import static org.apache.uima.cas.impl.S
 import static org.apache.uima.cas.impl.SlotKinds.SlotKind.Slot_ShortRef;
 import static org.apache.uima.cas.impl.SlotKinds.SlotKind.Slot_StrRef;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodType;
 import java.lang.invoke.MutableCallSite;
 import java.lang.ref.WeakReference;
@@ -146,6 +148,8 @@ public class TypeSystemImpl implements T
 //  private final static boolean IS_DECOMPILE_JCAS = Misc.getNoValueSystemProperty(DECOMPILE_JCAS);
 //  private final static Set<String> decompiled = (IS_DECOMPILE_JCAS) ? new HashSet<String>(256) : null;
     
+  static private final MethodHandle MHC_MINUS_1 = MethodHandles.constant(int.class, -1);
+  
   /**
    * Type code that is returned on unknown type names.
    */
@@ -2637,7 +2641,8 @@ public class TypeSystemImpl implements T
    * @return the created callsite
    */
   public static MutableCallSite createCallSite(Class<? extends TOP> clazz, String featName) {
-    MutableCallSite callSite = new MutableCallSite(MethodType.methodType(int.class));    
+    MutableCallSite callSite = new MutableCallSite(MethodType.methodType(int.class)); 
+    callSite.setTarget(MHC_MINUS_1);  // for error checking
     ArrayList<Entry<String, MutableCallSite>> callSitesForType = FSClassRegistry.callSites_all_JCasClasses.computeIfAbsent(clazz, k -> new ArrayList<>());
     callSitesForType.add(new AbstractMap.SimpleEntry<String, MutableCallSite>(featName, callSite));
     return callSite;

Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties?rev=1808758&r1=1808757&r2=1808758&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties Mon Sep 18 18:45:34 2017
@@ -530,7 +530,7 @@ JCAS_FEATURE_WRONG_TYPE = The JCAS range
 TYPEORDER_UNKNOWN_TYPE = The type sort order cannot be built because type {0} is unknown.
 MUST_COMMIT_TYPE_SYSTEM = Type system has not been committed. The base index cannot be created.
 JCAS_NO_TYPE = Cannot do feature accessing for a JCas class, because it is not associated with a committed UIMA Type, either because the type doesn''t exist, or hasn''t been committed.
-
+JCAS_INCOMPATIBLE_TYPE_SYSTEMS = Loaded JCas Type {0} has feature {1} with two different type systems having different offsets; this is not supported.
 
 #------------------------------------------------------------------------
 # CAS runtime exceptions