Repository: mit-cml/appinventor-sources
Issue: Build error when compiling official Look and PersonalImageClassifier extensions

**Describe the bug**

Compilation of official Look and PersonalImageClassifier extensions consistently fails.

**Affects**

Look and PersonalImageClassifier extensions cannot be compiled for use with the latest AppInventor source code.

- [ ] Designer
- [ ] Blocks editor
- [ ] Companion
- [ ] Compiled apps
- [ ] Buildserver
- [x] Other... (please describe)

**Expected behavior**

Look and PersonalImageClassifier extensions can be successfully built, and corresponding aix files are located at appinventor-sources/appinventor/components/build/extensions

**Steps to reproduce**

step 1: check out App Inventor source code from its main github branch (the latest code)

step 2: check out Look and PersonalImageClassifier extensions source code from official github 

step 3: copy Look and PersonalImageClassifier source code to appinventor-sources/appinventor/components/src/edu/mit/appinventor/ai/look and appinventor-sources/appinventor/components/src/edu/mit/appinventor/ai/personalimageclassifier respectively

step 4: cd appinventor-sources/appinventor/components/

step 5: execute "ant extensions"

step 6: build error as follows -

ExternalComponentGenerator:
    [mkdir] Created dir: /home/ubuntu/appinventor-sources/appinventor/components/build/classes/ExternalComponentGenerator
    [mkdir] Created dir: /home/ubuntu/appinventor-sources/appinventor/components/build/externalComponents
    [mkdir] Created dir: /home/ubuntu/appinventor-sources/appinventor/components/build/externalComponents-class
    [javac] Compiling 1 source file to /home/ubuntu/appinventor-sources/appinventor/components/build/classes/ExternalComponentGenerator
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
    [javac] 1 warning
     [java] 
     [java] Extensions : Generating extensions
     [java] 
     [java] Extensions : Generating files [edu.mit.appinventor.ai.personalimageclassifier]
     [java] Extensions : Copying file /home/ubuntu/appinventor-sources/appinventor/components/build/externalComponents/../../src/edu/mit/appinventor/ai/personalimageclassifier/aiwebres/glasses.png
     [java] java.lang.StringIndexOutOfBoundsException: String index out of range: -1
     [java] 	at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:194)
     [java] 	at org.apache.tools.ant.taskdefs.Java.run(Java.java:861)
     [java] 	at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:231)
     [java] 	at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135)
     [java] 	at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
     [java] 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
     [java] 	at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
     [java] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     [java] 	at java.lang.reflect.Method.invoke(Method.java:498)
     [java] 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
     [java] 	at org.apache.tools.ant.Task.perform(Task.java:350)
     [java] 	at org.apache.tools.ant.Target.execute(Target.java:449)
     [java] 	at org.apache.tools.ant.Target.performTasks(Target.java:470)
     [java] 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
     [java] 	at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:36)
     [java] 	at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
     [java] 	at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:437)
     [java] 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
     [java] 	at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
     [java] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     [java] 	at java.lang.reflect.Method.invoke(Method.java:498)
     [java] 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
     [java] 	at org.apache.tools.ant.Task.perform(Task.java:350)
     [java] 	at org.apache.tools.ant.Target.execute(Target.java:449)
     [java] 	at org.apache.tools.ant.Target.performTasks(Target.java:470)
     [java] 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
     [java] 	at org.apache.tools.ant.Project.executeTarget(Project.java:1361)
     [java] 	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
     [java] 	at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
     [java] 	at org.apache.tools.ant.Main.runBuild(Main.java:834)
     [java] 	at org.apache.tools.ant.Main.startAnt(Main.java:223)
     [java] 	at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
     [java] 	at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
     [java] Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
     [java] 	at java.lang.String.substring(String.java:1967)
     [java] 	at com.google.appinventor.components.scripts.ExternalComponentGenerator.getClassPackage(ExternalComponentGenerator.java:388)
     [java] 	at com.google.appinventor.components.scripts.ExternalComponentGenerator.isRelatedExternalClass(ExternalComponentGenerator.java:376)
     [java] 	at com.google.appinventor.components.scripts.ExternalComponentGenerator.copyRelatedExternalClasses(ExternalComponentGenerator.java:348)
     [java] 	at com.google.appinventor.components.scripts.ExternalComponentGenerator.generateExternalComponentBuildFiles(ExternalComponentGenerator.java:163)
     [java] 	at com.google.appinventor.components.scripts.ExternalComponentGenerator.generateAllExtensions(ExternalComponentGenerator.java:113)
     [java] 	at com.google.appinventor.components.scripts.ExternalComponentGenerator.main(ExternalComponentGenerator.java:71)
     [java] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     [java] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     [java] 	at java.lang.reflect.Method.invoke(Method.java:498)
     [java] 	at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:218)
     [java] 	at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:155)
     [java] 	... 32 more
     [java] Java Result: -1

Changed files:
appinventor/components/src/com/google/appinventor/components/scripts/ExternalComponentGenerator.java

diff --git a/appinventor/components/src/com/google/appinventor/components/scripts/ExternalComponentGenerator.java b/appinventor/components/src/com/google/appinventor/components/scripts/ExternalComponentGenerator.java
index 7cee62565..041f90d03 100644
--- a/appinventor/components/src/com/google/appinventor/components/scripts/ExternalComponentGenerator.java
+++ b/appinventor/components/src/com/google/appinventor/components/scripts/ExternalComponentGenerator.java
@@ -371,6 +371,9 @@ public class ExternalComponentGenerator {
    * {@code extensionPackage}, {@code false} otherwise
    */
   private static boolean isRelatedExternalClass(final String testClassAbsolutePath, final String extensionPackage ) {
+    if (!testClassAbsolutePath.endsWith(".class")) {  // Ignore things that aren't class files...
+      return false;
+    }
     String componentPackagePath = extensionPackage.replace(".", File.separator);
 
     String testClassPath = getClassPackage(testClassAbsolutePath);