Author: schor
Date: Wed Sep 15 15:46:27 2010
New Revision: 997372
URL: http://svn.apache.org/viewvc?rev=997372&view=rev
Log:
[UIMA-1874] add error message for missing context and result spec due to
failing to call super.xxx methods in Annotator overrides. added a test case
Added:
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnnotatorMissingSuper.java
Modified:
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/UIMARuntimeException.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_component/AnalysisComponent_ImplBase.java
uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java
Modified:
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/UIMARuntimeException.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/UIMARuntimeException.java?rev=997372&r1=997371&r2=997372&view=diff
==============================================================================
---
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/UIMARuntimeException.java
(original)
+++
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/UIMARuntimeException.java
Wed Sep 15 15:46:27 2010
@@ -101,6 +101,18 @@ public class UIMARuntimeException extend
public static final String FEATURE_NOT_FOUND_DURING_CAS_COPY =
"feature_not_found_during_cas_copy";
/**
+ * Message key for a standard UIMA exception message:
+ * Saved UIMA context is null; probable cause: Annotator initialize(context)
method failed to call super.initialize(context).
+ */
+ public static final String UIMA_CONTEXT_NULL = "uima_context_null";
+
+ /**
+ * Message key for a standard UIMA exception message:
+ * Saved result specification is null; probable cause: Annotator overrode
setResultSpecification(spec) but failed to call
super.setResultSpecification(spec).
+ */
+ public static final String RESULT_SPEC_NULL = "result_spec_null";
+
+ /**
* Creates a new exception with a null message.
*/
public UIMARuntimeException() {
Modified:
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_component/AnalysisComponent_ImplBase.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_component/AnalysisComponent_ImplBase.java?rev=997372&r1=997371&r2=997372&view=diff
==============================================================================
---
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_component/AnalysisComponent_ImplBase.java
(original)
+++
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_component/AnalysisComponent_ImplBase.java
Wed Sep 15 15:46:27 2010
@@ -19,6 +19,7 @@
package org.apache.uima.analysis_component;
+import org.apache.uima.UIMARuntimeException;
import org.apache.uima.UimaContext;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.analysis_engine.ResultSpecification;
@@ -61,7 +62,7 @@ public abstract class AnalysisComponent_
*/
public void reconfigure() throws ResourceConfigurationException,
ResourceInitializationException {
destroy();
- initialize(mContext);
+ initialize(getContext());
}
/*
@@ -110,6 +111,10 @@ public abstract class AnalysisComponent_
* @return the UimaContext for this AnalysisComponent
*/
protected final UimaContext getContext() {
+ if (null == mContext) {
+ // wrapped in RuntimeException because we don't want to change the API
of this method
+ throw new UIMARuntimeException(UIMARuntimeException.UIMA_CONTEXT_NULL,
new Object[] {} );
+ }
return mContext;
}
@@ -122,6 +127,10 @@ public abstract class AnalysisComponent_
* @return the ResultSpecification for this Analysis Component to use.
*/
protected ResultSpecification getResultSpecification() {
+ if (null == mResultSpecification) {
+ // wrapped in RuntimeException because we don't want to change the API
of this method
+ throw new UIMARuntimeException(UIMARuntimeException.RESULT_SPEC_NULL,
new Object[] {} );
+ }
return mResultSpecification;
}
}
Modified:
uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties?rev=997372&r1=997371&r2=997372&view=diff
==============================================================================
---
uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties
(original)
+++
uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties
Wed Sep 15 15:46:27 2010
@@ -43,6 +43,10 @@ type_not_found_during_cas_copy = Attempt
feature_not_found_during_cas_copy = Attempted to copy a Feature "{0}", which
is not defined in the type system of the destination CAS.
+uima_context_null = Saved UIMA context is null; probable cause: Annotator''s
initialize(context) method failed to call super.initialize(context).
+
+result_spec_null = Saved result specification is null; probable cause:
Annotator overrode setResultSpecification(spec) but failed to call
super.setResultSpecification(spec).
+
#--------------------------
#UIMA_IllegalStateException
#--------------------------
Modified:
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java?rev=997372&r1=997371&r2=997372&view=diff
==============================================================================
---
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java
(original)
+++
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java
Wed Sep 15 15:46:27 2010
@@ -1447,4 +1447,21 @@ public class AnalysisEngine_implTest ext
JUnitExtension.handleException(e);
}
}
+
+ public void testMissingSuper() throws Exception {
+ try {
+ // initialize simple primitive TextAnalysisEngine
+ AnalysisEngine ae1 = new PrimitiveAnalysisEngine_impl();
+ AnalysisEngineDescription primitiveDesc = new
AnalysisEngineDescription_impl();
+ primitiveDesc.setFrameworkImplementation(Constants.JAVA_FRAMEWORK_NAME);
+ primitiveDesc.setPrimitive(true);
+
primitiveDesc.setAnnotatorImplementationName(AnnotatorMissingSuper.class.getCanonicalName());
+ ae1.initialize(primitiveDesc, null);
+ ae1.process(ae1.newCAS());
+ } catch (Exception e) {
+ JUnitExtension.handleException(e);
+ }
+ }
+
+
}
Added:
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnnotatorMissingSuper.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnnotatorMissingSuper.java?rev=997372&view=auto
==============================================================================
---
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnnotatorMissingSuper.java
(added)
+++
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnnotatorMissingSuper.java
Wed Sep 15 15:46:27 2010
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.analysis_engine.impl;
+
+import org.apache.uima.UIMARuntimeException;
+import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_component.CasAnnotator_ImplBase;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.analysis_engine.ResultSpecification;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.resource.ResourceInitializationException;
+
+public class AnnotatorMissingSuper extends CasAnnotator_ImplBase {
+
+ @Override
+ public void process(CAS aCAS) throws AnalysisEngineProcessException {
+ boolean caught = false;
+ try {
+ getContext();
+ } catch (UIMARuntimeException e) {
+ caught = true;
+ }
+ if (!caught) {
+ throw new RuntimeException("failed to throw for missing context");
+ }
+ caught = false;
+ try {
+ getResultSpecification();
+ } catch (UIMARuntimeException e) {
+ caught = true;
+ }
+ if (!caught) {
+ throw new RuntimeException("failed to throw for missing resultSpec");
+ }
+ }
+
+ @Override
+ public void initialize(UimaContext aContext) throws
ResourceInitializationException {
+
+ }
+
+ @Override
+ public void setResultSpecification(ResultSpecification aResultSpec) {
+
+ }
+
+
+}