Add check that TypeIndex is valid in StringByTypeIdx.

StringByTypeIdx should fail gracefully if given a bad TypeIndex. This
adds a check that the TypeIndex is valid before getting its TypeId.

This fixes a regression that removed this check when it was refactored
in this CL: https://android-review.googlesource.com/#/c/243493/

Bug: 37287051
Test: mm -j31 test-art-host-gtest-dex_file_test
Change-Id: Ib68cb8135011f5f30335251583e181b089982754
diff --git a/runtime/dex_file_test.cc b/runtime/dex_file_test.cc
index 3f7461c..f811287 100644
--- a/runtime/dex_file_test.cc
+++ b/runtime/dex_file_test.cc
@@ -591,4 +591,11 @@
   EXPECT_EQ(raw, nullptr);
 }
 
+TEST_F(DexFileTest, GetStringWithNoIndex) {
+  ScratchFile tmp;
+  std::unique_ptr<const DexFile> raw(OpenDexFileBase64(kRawDex, tmp.GetFilename().c_str()));
+  dex::TypeIndex idx;
+  EXPECT_EQ(raw->StringByTypeIdx(idx), nullptr);
+}
+
 }  // namespace art