Fix accidental infinite recursion in determining if an Interface is java

compatible or not. If that interface's methods (or something even farther
downstream) references the original interface we'll recurse indefinitely without
this fix.

Change-Id: Ib94dfec2dd32c00f1ee03c49d13f59f6e31f6d8d
diff --git a/Interface.cpp b/Interface.cpp
index 02e3504..52c1963 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -6,11 +6,10 @@
 
 namespace android {
 
-Interface::Interface(
-        Interface *super,
-        AnnotationVector *annotations)
-        : mSuperType(super),
-          mAnnotationsByName(annotations) {
+Interface::Interface(Interface *super, AnnotationVector *annotations)
+    : mSuperType(super),
+      mAnnotationsByName(annotations),
+      mIsJavaCompatibleInProgress(false) {
 }
 
 void Interface::addMethod(Method *method) {
@@ -133,16 +132,31 @@
 }
 
 bool Interface::isJavaCompatible() const {
+    if (mIsJavaCompatibleInProgress) {
+        // We're currently trying to determine if this Interface is
+        // java-compatible and something is referencing this interface through
+        // one of its methods. Assume we'll ultimately succeed, if we were wrong
+        // the original invocation of Interface::isJavaCompatible() will then
+        // return the correct "false" result.
+        return true;
+    }
+
+    mIsJavaCompatibleInProgress = true;
+
     if (!Scope::isJavaCompatible()) {
+        mIsJavaCompatibleInProgress = false;
         return false;
     }
 
     for (const auto &method : mMethods) {
         if (!method->isJavaCompatible()) {
+            mIsJavaCompatibleInProgress = false;
             return false;
         }
     }
 
+    mIsJavaCompatibleInProgress = false;
+
     return true;
 }