Internal cleanup.
authorA. Unique TensorFlower <gardener@tensorflow.org>
Thu, 19 Apr 2018 18:57:48 +0000 (11:57 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Thu, 19 Apr 2018 19:04:02 +0000 (12:04 -0700)
PiperOrigin-RevId: 193552240

tensorflow/contrib/lite/java/src/main/java/org/tensorflow/lite/DataType.java
tensorflow/contrib/lite/java/src/main/java/org/tensorflow/lite/Interpreter.java
tensorflow/contrib/lite/java/src/main/java/org/tensorflow/lite/NativeInterpreterWrapper.java
tensorflow/contrib/lite/java/src/main/java/org/tensorflow/lite/Tensor.java
tensorflow/contrib/lite/java/src/main/native/exception_jni.cc
tensorflow/contrib/lite/java/src/main/native/nativeinterpreterwrapper_jni.cc
tensorflow/contrib/lite/java/src/main/native/tensor_jni.cc
tensorflow/contrib/lite/java/src/test/java/org/tensorflow/lite/NativeInterpreterWrapperTest.java

index fc16488..75334cd 100644 (file)
@@ -51,7 +51,11 @@ enum DataType {
       }
     }
     throw new IllegalArgumentException(
-        "DataType " + c + " is not recognized in Java (version " + TensorFlowLite.version() + ")");
+        "DataType error: DataType "
+            + c
+            + " is not recognized in Java (version "
+            + TensorFlowLite.version()
+            + ")");
   }
 
   /** Returns byte size of the type. */
@@ -68,7 +72,8 @@ enum DataType {
       case BYTEBUFFER:
         return 1;
     }
-    throw new IllegalArgumentException("DataType " + this + " is not supported yet");
+    throw new IllegalArgumentException(
+        "DataType error: DataType " + this + " is not supported yet");
   }
 
   /** Gets string names of the data type. */
@@ -85,7 +90,8 @@ enum DataType {
       case BYTEBUFFER:
         return "ByteBuffer";
     }
-    throw new IllegalArgumentException("DataType " + this + " is not supported yet");
+    throw new IllegalArgumentException(
+        "DataType error: DataType " + this + " is not supported yet");
   }
 
   // Cached to avoid copying it
index a33959d..e915e65 100644 (file)
@@ -137,17 +137,19 @@ public final class Interpreter implements AutoCloseable {
   public void runForMultipleInputsOutputs(
       @NonNull Object[] inputs, @NonNull Map<Integer, Object> outputs) {
     if (wrapper == null) {
-      throw new IllegalStateException("The Interpreter has already been closed.");
+      throw new IllegalStateException("Internal error: The Interpreter has already been closed.");
     }
     Tensor[] tensors = wrapper.run(inputs);
     if (outputs == null || tensors == null || outputs.size() > tensors.length) {
-      throw new IllegalArgumentException("Outputs do not match with model outputs.");
+      throw new IllegalArgumentException("Output error: Outputs do not match with model outputs.");
     }
     final int size = tensors.length;
     for (Integer idx : outputs.keySet()) {
       if (idx == null || idx < 0 || idx >= size) {
         throw new IllegalArgumentException(
-            String.format("Invalid index of output %d (should be in range [0, %d))", idx, size));
+            String.format(
+                "Output error: Invalid index of output %d (should be in range [0, %d))",
+                idx, size));
       }
       tensors[idx].copyTo(outputs.get(idx));
     }
@@ -160,7 +162,7 @@ public final class Interpreter implements AutoCloseable {
    */
   public void resizeInput(int idx, @NonNull int[] dims) {
     if (wrapper == null) {
-      throw new IllegalStateException("The Interpreter has already been closed.");
+      throw new IllegalStateException("Internal error: The Interpreter has already been closed.");
     }
     wrapper.resizeInput(idx, dims);
   }
@@ -173,7 +175,7 @@ public final class Interpreter implements AutoCloseable {
    */
   public int getInputIndex(String opName) {
     if (wrapper == null) {
-      throw new IllegalStateException("The Interpreter has already been closed.");
+      throw new IllegalStateException("Internal error: The Interpreter has already been closed.");
     }
     return wrapper.getInputIndex(opName);
   }
@@ -186,7 +188,7 @@ public final class Interpreter implements AutoCloseable {
    */
   public int getOutputIndex(String opName) {
     if (wrapper == null) {
-      throw new IllegalStateException("The Interpreter has already been closed.");
+      throw new IllegalStateException("Internal error: The Interpreter has already been closed.");
     }
     return wrapper.getOutputIndex(opName);
   }
@@ -198,7 +200,7 @@ public final class Interpreter implements AutoCloseable {
    */
   public Long getLastNativeInferenceDurationNanoseconds() {
     if (wrapper == null) {
-      throw new IllegalStateException("The interpreter has already been closed.");
+      throw new IllegalStateException("Internal error: The interpreter has already been closed.");
     }
     return wrapper.getLastNativeInferenceDurationNanoseconds();
   }
@@ -208,7 +210,8 @@ public final class Interpreter implements AutoCloseable {
     if (wrapper != null) {
       wrapper.setUseNNAPI(useNNAPI);
     } else {
-      throw new IllegalStateException("NativeInterpreterWrapper has already been closed.");
+      throw new IllegalStateException(
+          "Internal error: NativeInterpreterWrapper has already been closed.");
     }
   }
 
index fc8187a..dfc8ac1 100644 (file)
@@ -80,7 +80,7 @@ final class NativeInterpreterWrapper implements AutoCloseable {
   /** Sets inputs, runs model inference and returns outputs. */
   Tensor[] run(Object[] inputs) {
     if (inputs == null || inputs.length == 0) {
-      throw new IllegalArgumentException("Invalid inputs. Inputs should not be null or empty.");
+      throw new IllegalArgumentException("Input error: Inputs should not be null or empty.");
     }
     int[] dataTypes = new int[inputs.length];
     Object[] sizes = new Object[inputs.length];
@@ -92,7 +92,7 @@ final class NativeInterpreterWrapper implements AutoCloseable {
         ByteBuffer buffer = (ByteBuffer) inputs[i];
         if (buffer.order() != ByteOrder.nativeOrder()) {
           throw new IllegalArgumentException(
-              "Invalid ByteBuffer. It shoud use ByteOrder.nativeOrder().");
+              "Input error: ByteBuffer shoud use ByteOrder.nativeOrder().");
         }
         numsOfBytes[i] = buffer.limit();
         sizes[i] = getInputDims(interpreterHandle, i, numsOfBytes[i]);
@@ -103,7 +103,7 @@ final class NativeInterpreterWrapper implements AutoCloseable {
       } else {
         throw new IllegalArgumentException(
             String.format(
-                "%d-th element of the %d inputs is not an array or a ByteBuffer.",
+                "Input error: %d-th element of the %d inputs is not an array or a ByteBuffer.",
                 i, inputs.length));
       }
     }
@@ -119,7 +119,7 @@ final class NativeInterpreterWrapper implements AutoCloseable {
             this,
             isMemoryAllocated);
     if (outputsHandles == null || outputsHandles.length == 0) {
-      throw new IllegalStateException("Interpreter has no outputs.");
+      throw new IllegalStateException("Internal error: Interpreter has no outputs.");
     }
     isMemoryAllocated = true;
     Tensor[] outputs = new Tensor[outputsHandles.length];
@@ -169,7 +169,8 @@ final class NativeInterpreterWrapper implements AutoCloseable {
     } else {
       throw new IllegalArgumentException(
           String.format(
-              "%s is not a valid name for any input. The indexes of the inputs are %s",
+              "Input error: %s is not a valid name for any input. "
+                  + "The indexes of the inputs are %s",
               name, inputsIndexes.toString()));
     }
   }
@@ -190,7 +191,8 @@ final class NativeInterpreterWrapper implements AutoCloseable {
     } else {
       throw new IllegalArgumentException(
           String.format(
-              "%s is not a valid name for any output. The indexes of the outputs are %s",
+              "Input error: %s is not a valid name for any output. "
+                  + "The indexes of the outputs are %s",
               name, outputsIndexes.toString()));
     }
   }
@@ -229,7 +231,8 @@ final class NativeInterpreterWrapper implements AutoCloseable {
         return DataType.BYTEBUFFER;
       }
     }
-    throw new IllegalArgumentException("cannot resolve DataType of " + o.getClass().getName());
+    throw new IllegalArgumentException(
+        "DataType error: cannot resolve DataType of " + o.getClass().getName());
   }
 
   /** Returns the shape of an object as an int array. */
@@ -245,7 +248,7 @@ final class NativeInterpreterWrapper implements AutoCloseable {
       return 0;
     }
     if (Array.getLength(o) == 0) {
-      throw new IllegalArgumentException("array lengths cannot be 0.");
+      throw new IllegalArgumentException("Array lengths cannot be 0.");
     }
     return 1 + numDimensions(Array.get(o, 0));
   }
@@ -259,7 +262,7 @@ final class NativeInterpreterWrapper implements AutoCloseable {
       shape[dim] = len;
     } else if (shape[dim] != len) {
       throw new IllegalArgumentException(
-          String.format("mismatched lengths (%d and %d) in dimension %d", shape[dim], len, dim));
+          String.format("Mismatched lengths (%d and %d) in dimension %d", shape[dim], len, dim));
     }
     for (int i = 0; i < len; ++i) {
       fillShape(Array.get(o, i), dim + 1, shape);
index 54ace6c..09e887a 100644 (file)
@@ -34,15 +34,16 @@ final class Tensor {
     if (NativeInterpreterWrapper.dataTypeOf(dst) != dtype) {
       throw new IllegalArgumentException(
           String.format(
-              "Cannot convert an TensorFlowLite tensor with type %s to a Java object of "
-                  + "type %s (which is compatible with the TensorFlowLite type %s)",
+              "Output error: Cannot convert an TensorFlowLite tensor with type %s to a Java "
+                  + "object of type %s (which is compatible with the TensorFlowLite type %s)",
               dtype, dst.getClass().getName(), NativeInterpreterWrapper.dataTypeOf(dst)));
     }
     int[] dstShape = NativeInterpreterWrapper.shapeOf(dst);
     if (!Arrays.equals(dstShape, shapeCopy)) {
       throw new IllegalArgumentException(
           String.format(
-              "Shape of output target %s does not match with the shape of the Tensor %s.",
+              "Output error: Shape of output target %s does not match with the shape of the "
+                  + "Tensor %s.",
               Arrays.toString(dstShape), Arrays.toString(shapeCopy)));
     }
     readMultiDimensionalArray(nativeHandle, dst);
index 1578c9e..34d91be 100644 (file)
@@ -44,7 +44,8 @@ BufferErrorReporter::BufferErrorReporter(JNIEnv* env, int limit) {
   buffer_ = new char[limit];
   if (!buffer_) {
     throwException(env, kNullPointerException,
-                   "Malloc of BufferErrorReporter to hold %d char failed.",
+                   "Internal error: Malloc of BufferErrorReporter to hold %d "
+                   "char failed.",
                    limit);
     return;
   }
index 8442262..ccfdfd8 100644 (file)
@@ -22,7 +22,7 @@ const int kBufferSize = 256;
 tflite::Interpreter* convertLongToInterpreter(JNIEnv* env, jlong handle) {
   if (handle == 0) {
     throwException(env, kIllegalArgumentException,
-                   "Invalid handle to Interpreter.");
+                   "Internal error: Invalid handle to Interpreter.");
     return nullptr;
   }
   return reinterpret_cast<tflite::Interpreter*>(handle);
@@ -30,7 +30,8 @@ tflite::Interpreter* convertLongToInterpreter(JNIEnv* env, jlong handle) {
 
 tflite::FlatBufferModel* convertLongToModel(JNIEnv* env, jlong handle) {
   if (handle == 0) {
-    throwException(env, kIllegalArgumentException, "Invalid handle to model.");
+    throwException(env, kIllegalArgumentException,
+                   "Internal error: Invalid handle to model.");
     return nullptr;
   }
   return reinterpret_cast<tflite::FlatBufferModel*>(handle);
@@ -39,7 +40,7 @@ tflite::FlatBufferModel* convertLongToModel(JNIEnv* env, jlong handle) {
 BufferErrorReporter* convertLongToErrorReporter(JNIEnv* env, jlong handle) {
   if (handle == 0) {
     throwException(env, kIllegalArgumentException,
-                   "Invalid handle to ErrorReporter.");
+                   "Internal error: Invalid handle to ErrorReporter.");
     return nullptr;
   }
   return reinterpret_cast<BufferErrorReporter*>(handle);
@@ -51,7 +52,7 @@ std::vector<int> convertJIntArrayToVector(JNIEnv* env, jintArray inputs) {
   jint* ptr = env->GetIntArrayElements(inputs, nullptr);
   if (ptr == nullptr) {
     throwException(env, kIllegalArgumentException,
-                   "Empty dimensions of input array.");
+                   "Array has empty dimensions.");
     return {};
   }
   for (int i = 0; i < size; ++i) {
@@ -113,7 +114,7 @@ TfLiteStatus checkInputs(JNIEnv* env, tflite::Interpreter* interpreter,
                          jobjectArray sizes) {
   if (input_size != interpreter->inputs().size()) {
     throwException(env, kIllegalArgumentException,
-                   "Expected num of inputs is %d but got %d",
+                   "Input error: Expected num of inputs is %d but got %d",
                    interpreter->inputs().size(), input_size);
     return kTfLiteError;
   }
@@ -121,8 +122,9 @@ TfLiteStatus checkInputs(JNIEnv* env, tflite::Interpreter* interpreter,
       input_size != env->GetArrayLength(nums_of_bytes) ||
       input_size != env->GetArrayLength(values)) {
     throwException(env, kIllegalArgumentException,
-                   "Arrays in arguments should be of the same length, but got "
-                   "%d sizes, %d data_types, %d nums_of_bytes, and %d values",
+                   "Internal error: Arrays in arguments should be of the same "
+                   "length, but got %d sizes, %d data_types, %d nums_of_bytes, "
+                   "and %d values",
                    input_size, env->GetArrayLength(data_types),
                    env->GetArrayLength(nums_of_bytes),
                    env->GetArrayLength(values));
@@ -136,8 +138,8 @@ TfLiteStatus checkInputs(JNIEnv* env, tflite::Interpreter* interpreter,
     int num_dims = static_cast<int>(env->GetArrayLength(dims));
     if (target->dims->size != num_dims) {
       throwException(env, kIllegalArgumentException,
-                     "%d-th input should have %d dimensions, but found %d "
-                     "dimensions",
+                     "Input error: %d-th input should have %d dimensions, but "
+                     "found %d dimensions",
                      i, target->dims->size, num_dims);
       return kTfLiteError;
     }
@@ -150,7 +152,8 @@ TfLiteStatus checkInputs(JNIEnv* env, tflite::Interpreter* interpreter,
                   num_dims);
         printDims(obtained_dims.get(), kBufferSize, ptr, num_dims);
         throwException(env, kIllegalArgumentException,
-                       "%d-th input dimension should be [%s], but found [%s]",
+                       "Input error: %d-th input dimension should be [%s], but "
+                       "found [%s]",
                        i, expected_dims.get(), obtained_dims.get());
         env->ReleaseIntArrayElements(dims, ptr, JNI_ABORT);
         return kTfLiteError;
@@ -236,8 +239,8 @@ TfLiteStatus setInputs(JNIEnv* env, tflite::Interpreter* interpreter,
       TfLiteType type = resolveDataType(data_type[i]);
       if (type != target->type) {
         throwException(env, kIllegalArgumentException,
-                       "DataType (%d) of input data does not match with the "
-                       "DataType (%d) of model inputs.",
+                       "Input error: DataType (%d) of input data does not "
+                       "match with the DataType (%d) of model inputs.",
                        type, target->type);
         return kTfLiteError;
       }
@@ -270,7 +273,8 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_getInputNames(JNIEnv* env,
   jclass string_class = env->FindClass("java/lang/String");
   if (string_class == nullptr) {
     throwException(env, kUnsupportedOperationException,
-                   "Can not find java/lang/String class to get input names.");
+                   "Internal error: Can not find java/lang/String class to get "
+                   "input names.");
     return nullptr;
   }
   size_t size = interpreter->inputs().size();
@@ -292,7 +296,8 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_getOutputNames(JNIEnv* env,
   jclass string_class = env->FindClass("java/lang/String");
   if (string_class == nullptr) {
     throwException(env, kUnsupportedOperationException,
-                   "Can not find java/lang/String class to get output names.");
+                   "Internal error: Can not find java/lang/String class to get "
+                   "output names.");
     return nullptr;
   }
   size_t size = interpreter->outputs().size();
@@ -351,8 +356,8 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_createModel(
       path, verifier.get(), error_reporter);
   if (!model) {
     throwException(env, kIllegalArgumentException,
-                   "Contents of %s does not encode a valid TensorFlowLite "
-                   "model: %s",
+                   "Contents of %s does not encode a valid "
+                   "TensorFlowLite model: %s",
                    path, error_reporter->CachedErrorMessage());
     env->ReleaseStringUTFChars(model_file, path);
     return 0;
@@ -380,8 +385,8 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_createModelWithBuffer(
       buf, static_cast<size_t>(capacity), error_reporter);
   if (!model) {
     throwException(env, kIllegalArgumentException,
-                   "MappedByteBuffer does not encode a valid TensorFlowLite "
-                   "model: %s",
+                   "MappedByteBuffer does not encode a valid "
+                   "TensorFlowLite model: %s",
                    error_reporter->CachedErrorMessage());
     return 0;
   }
@@ -403,7 +408,7 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_createInterpreter(
       &interpreter, static_cast<int>(num_threads));
   if (status != kTfLiteOk) {
     throwException(env, kIllegalArgumentException,
-                   "Cannot create interpreter: %s",
+                   "Internal error: Cannot create interpreter: %s",
                    error_reporter->CachedErrorMessage());
     return 0;
   }
@@ -411,7 +416,7 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_createInterpreter(
   status = interpreter->AllocateTensors();
   if (status != kTfLiteOk) {
     throwException(env, kNullPointerException,
-                   "Can not allocate memory for the interpreter",
+                   "Internal error: Cannot allocate memory for the interpreter",
                    error_reporter->CachedErrorMessage());
     return 0;
   }
@@ -440,7 +445,8 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_run(
     // resizes inputs
     status = resizeInputs(env, interpreter, input_size, sizes);
     if (status != kTfLiteOk) {
-      throwException(env, kNullPointerException, "Can not resize the input: %s",
+      throwException(env, kNullPointerException,
+                     "Internal error: Can not resize the input: %s",
                      error_reporter->CachedErrorMessage());
       return nullptr;
     }
@@ -448,7 +454,8 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_run(
     status = interpreter->AllocateTensors();
     if (status != kTfLiteOk) {
       throwException(env, kNullPointerException,
-                     "Can not allocate memory for the given inputs: %s",
+                     "Internal error: Can not allocate memory for the given "
+                     "inputs: %s",
                      error_reporter->CachedErrorMessage());
       return nullptr;
     }
@@ -461,7 +468,7 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_run(
   // runs inference
   if (interpreter->Invoke() != kTfLiteOk) {
     throwException(env, kIllegalArgumentException,
-                   "Failed to run on the given Interpreter: %s",
+                   "Internal error: Failed to run on the given Interpreter: %s",
                    error_reporter->CachedErrorMessage());
     return nullptr;
   }
@@ -479,8 +486,9 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_run(
   // returns outputs
   const std::vector<int>& results = interpreter->outputs();
   if (results.empty()) {
-    throwException(env, kIllegalArgumentException,
-                   "The Interpreter does not have any outputs.");
+    throwException(
+        env, kIllegalArgumentException,
+        "Internal error: The Interpreter does not have any outputs.");
     return nullptr;
   }
   jlongArray outputs = env->NewLongArray(results.size());
@@ -501,7 +509,8 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_getInputDims(
   const int idx = static_cast<int>(input_idx);
   if (input_idx < 0 || input_idx >= interpreter->inputs().size()) {
     throwException(env, kIllegalArgumentException,
-                   "Out of range: Failed to get %d-th input out of %d inputs",
+                   "Input error: Out of range: Failed to get %d-th input out of"
+                   " %d inputs",
                    input_idx, interpreter->inputs().size());
     return nullptr;
   }
@@ -514,8 +523,8 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_getInputDims(
     }
     if (num_bytes != expected_num_bytes) {
       throwException(env, kIllegalArgumentException,
-                     "Failed to get input dimensions. %d-th input should have"
-                     " %d bytes, but found %d bytes.",
+                     "Input error: Failed to get input dimensions. %d-th input "
+                     "should have %d bytes, but found %d bytes.",
                      idx, expected_num_bytes, num_bytes);
       return nullptr;
     }
@@ -533,8 +542,8 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_getOutputDataType(
   const int idx = static_cast<int>(output_idx);
   if (output_idx < 0 || output_idx >= interpreter->outputs().size()) {
     throwException(env, kIllegalArgumentException,
-                   "Out of range: Failed to get %d-th output out of %d outputs",
-                   output_idx, interpreter->outputs().size());
+                   "Failed to get %d-th output out of %d outputs", output_idx,
+                   interpreter->outputs().size());
     return -1;
   }
   TfLiteTensor* target = interpreter->tensor(interpreter->outputs()[idx]);
@@ -555,7 +564,8 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_resizeInput(
   const int idx = static_cast<int>(input_idx);
   if (idx < 0 || idx >= interpreter->inputs().size()) {
     throwException(env, kIllegalArgumentException,
-                   "Can not resize %d-th input for a model having %d inputs.",
+                   "Input error: Can not resize %d-th input for a model having "
+                   "%d inputs.",
                    idx, interpreter->inputs().size());
     return JNI_FALSE;
   }
@@ -567,7 +577,7 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_resizeInput(
         interpreter->inputs()[idx], convertJIntArrayToVector(env, dims));
     if (status != kTfLiteOk) {
       throwException(env, kIllegalArgumentException,
-                     "Failed to resize %d-th input: %s", idx,
+                     "Internal error: Failed to resize %d-th input: %s", idx,
                      error_reporter->CachedErrorMessage());
       return JNI_FALSE;
     }
index 65126e7..17f4be0 100644 (file)
@@ -23,7 +23,7 @@ namespace {
 TfLiteTensor* convertLongToTensor(JNIEnv* env, jlong handle) {
   if (handle == 0) {
     throwException(env, kIllegalArgumentException,
-                   "Invalid handle to TfLiteTensor.");
+                   "Internal error: Invalid handle to TfLiteTensor.");
     return nullptr;
   }
   return reinterpret_cast<TfLiteTensor*>(handle);
@@ -36,7 +36,8 @@ size_t writeOneDimensionalArray(JNIEnv* env, jobject object, TfLiteType type,
   size_t to_copy = num_elements * elementByteSize(type);
   if (to_copy > dst_size) {
     throwException(env, kIllegalStateException,
-                   "cannot write Java array of %d bytes to Tensor of %d bytes",
+                   "Internal error: cannot write Java array of %d bytes to "
+                   "Tensor of %d bytes",
                    to_copy, dst_size);
     return 0;
   }
@@ -71,10 +72,10 @@ size_t writeOneDimensionalArray(JNIEnv* env, jobject object, TfLiteType type,
     }
     default: {
       throwException(env, kUnsupportedOperationException,
-                     "TensorFlowLite currently supports float (32 bits), "
-                     "int (32 bits), byte (8 bits), and long (64 bits), "
-                     "support for other types (DataType %d in this case) will "
-                     "be added in the future",
+                     "DataType error: TensorFlowLite currently supports float "
+                     "(32 bits), int (32 bits), byte (8 bits), and long "
+                     "(64 bits), support for other types (DataType %d in this "
+                     "case) will be added in the future",
                      kTfLiteFloat32, type);
       return 0;
     }
@@ -88,8 +89,9 @@ size_t readOneDimensionalArray(JNIEnv* env, TfLiteType data_type,
   if (size > src_size) {
     throwException(
         env, kIllegalStateException,
-        "cannot fill a Java array of %d bytes with a Tensor of %d bytes", size,
-        src_size);
+        "Internal error: cannot fill a Java array of %d bytes with a Tensor of "
+        "%d bytes",
+        size, src_size);
     return 0;
   }
   switch (data_type) {
@@ -117,8 +119,8 @@ size_t readOneDimensionalArray(JNIEnv* env, TfLiteType data_type,
       return size;
     }
     default: {
-      throwException(env, kIllegalStateException, "invalid DataType(%d)",
-                     data_type);
+      throwException(env, kIllegalStateException,
+                     "DataType error: invalid DataType(%d)", data_type);
     }
   }
   return 0;
@@ -152,19 +154,22 @@ size_t elementByteSize(TfLiteType data_type) {
   switch (data_type) {
     case kTfLiteFloat32:
       static_assert(sizeof(jfloat) == 4,
-                    "Java float not compatible with kTfLiteFloat");
+                    "Interal error: Java float not compatible with "
+                    "kTfLiteFloat");
       return 4;
     case kTfLiteInt32:
       static_assert(sizeof(jint) == 4,
-                    "Java int not compatible with kTfLiteInt");
+                    "Interal error: Java int not compatible with kTfLiteInt");
       return 4;
     case kTfLiteUInt8:
       static_assert(sizeof(jbyte) == 1,
-                    "Java byte not compatible with kTfLiteUInt8");
+                    "Interal error: Java byte not compatible with "
+                    "kTfLiteUInt8");
       return 1;
     case kTfLiteInt64:
       static_assert(sizeof(jlong) == 8,
-                    "Java long not compatible with kTfLiteInt64");
+                    "Interal error: Java long not compatible with "
+                    "kTfLiteInt64");
       return 8;
     default:
       return 0;
@@ -212,7 +217,7 @@ Java_org_tensorflow_lite_Tensor_readMultiDimensionalArray(JNIEnv* env,
   int num_dims = tensor->dims->size;
   if (num_dims == 0) {
     throwException(env, kIllegalArgumentException,
-                   "copyTo() is not meant for scalar Tensors.");
+                   "Internal error: Cannot copy empty/scalar Tensors.");
     return;
   }
   readMultiDimensionalArray(env, tensor->type, tensor->data.raw, tensor->bytes,
index dbe45e5..7c00d31 100644 (file)
@@ -321,9 +321,7 @@ public final class NativeInterpreterWrapperTest {
       wrapper.run(inputs);
       fail();
     } catch (IllegalArgumentException e) {
-      assertThat(e)
-          .hasMessageThat()
-          .contains("Invalid inputs. Inputs should not be null or empty.");
+      assertThat(e).hasMessageThat().contains("Inputs should not be null or empty.");
     }
     wrapper.close();
   }
@@ -440,7 +438,7 @@ public final class NativeInterpreterWrapperTest {
       NativeInterpreterWrapper.numDimensions(emptyArray);
       fail();
     } catch (IllegalArgumentException e) {
-      assertThat(e).hasMessageThat().contains("array lengths cannot be 0.");
+      assertThat(e).hasMessageThat().contains("Array lengths cannot be 0.");
     }
   }