Support a dex file without an extension.

For such a dex file, just append ".odex" to the filename.

Bug: 295161587
Test: atest art_standalone_runtime_tests
Test: atest CtsCompilationTestCases
Change-Id: Ibf07811d18105197818aa36ccae7588f9713c142
Merged-In: Ibf07811d18105197818aa36ccae7588f9713c142
diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc
index ed36df4..1087ae7 100644
--- a/runtime/oat_file_assistant.cc
+++ b/runtime/oat_file_assistant.cc
@@ -651,11 +651,7 @@
   // Get the base part of the file without the extension.
   std::string file = location.substr(pos + 1);
   pos = file.rfind('.');
-  if (pos == std::string::npos) {
-    *error_msg = "Dex location " + location + " has no extension.";
-    return false;
-  }
-  std::string base = file.substr(0, pos);
+  std::string base = pos != std::string::npos ? file.substr(0, pos) : file;
 
   *odex_filename = dir + "/" + base + ".odex";
   return true;
diff --git a/runtime/oat_file_assistant_test.cc b/runtime/oat_file_assistant_test.cc
index c1f2d3e..03306a9 100644
--- a/runtime/oat_file_assistant_test.cc
+++ b/runtime/oat_file_assistant_test.cc
@@ -1643,17 +1643,21 @@
   std::string odex_file;
 
   EXPECT_TRUE(OatFileAssistant::DexLocationToOdexFilename(
-        "/foo/bar/baz.jar", InstructionSet::kArm, &odex_file, &error_msg)) << error_msg;
+      "/foo/bar/baz.jar", InstructionSet::kArm, &odex_file, &error_msg))
+      << error_msg;
   EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file);
 
   EXPECT_TRUE(OatFileAssistant::DexLocationToOdexFilename(
-        "/foo/bar/baz.funnyext", InstructionSet::kArm, &odex_file, &error_msg)) << error_msg;
+      "/foo/bar/baz.funnyext", InstructionSet::kArm, &odex_file, &error_msg))
+      << error_msg;
   EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file);
 
   EXPECT_FALSE(OatFileAssistant::DexLocationToOdexFilename(
-        "nopath.jar", InstructionSet::kArm, &odex_file, &error_msg));
-  EXPECT_FALSE(OatFileAssistant::DexLocationToOdexFilename(
-        "/foo/bar/baz_noext", InstructionSet::kArm, &odex_file, &error_msg));
+      "nopath.jar", InstructionSet::kArm, &odex_file, &error_msg));
+
+  EXPECT_TRUE(OatFileAssistant::DexLocationToOdexFilename(
+      "/foo/bar/baz_noext", InstructionSet::kArm, &odex_file, &error_msg));
+  EXPECT_EQ("/foo/bar/oat/arm/baz_noext.odex", odex_file);
 }
 
 // Verify the dexopt status values from dalvik.system.DexFile