Repository: square/wire
Issue: Inconsistent fromValue() implementation for enums in Kotlin and Java

Java returns null for unknown tags:
```java
public static NestedEnum fromValue(int value) {
  switch (value) {
    case 1: return A;
    default: return null;
  }
}
```
While Kotlin throws:
```kotlin
fun fromValue(value: Int): NestedEnum = when (value) {
  1 -> A
  else -> throw IllegalArgumentException("""Unexpected value: $value""")
}
```
Kotlin implementation should be changed to mirror Java.

Changed files:
wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinGenerator.kt
wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/MessageWithStatus.kt
wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/OptionalEnumUser.kt
wire-moshi-adapter/src/test/java/com/squareup/wire/protos/geology/kotlin/Period.kt
wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/person/Person.kt
wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/foreign/ForeignEnum.kt
wire-moshi-adapter/src/test/java/com/squareup/wire/protos/person/kotlin/Person.kt
wire-moshi-adapter/src/test/java/com/squareup/wire/protos/person/javainteropkotlin/Person.kt
wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/OtherMessageWithStatus.kt
wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/simple/SimpleMessage.kt
wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt
wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinGeneratorTest.kt
wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/person/Person.kt
wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/MessageWithStatus.kt
wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt
wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/DeprecatedEnum.kt
wire-tests/src/jvmKotlinAndroidTest/proto-kotlin/com/squareup/wire/protos/kotlin/person/Person.kt
wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/OtherMessageWithStatus.kt
wire-moshi-adapter/src/test/java/com/squareup/wire/protos/geology/javainteropkotlin/Period.kt

diff --git a/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinGenerator.kt b/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinGenerator.kt
index 61338be0e..a7d0acabb 100644
--- a/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinGenerator.kt
+++ b/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinGenerator.kt
@@ -1136,13 +1136,13 @@ class KotlinGenerator private constructor(
     val fromValue = FunSpec.builder("fromValue")
         .jvmStatic()
         .addParameter(valueName, Int::class)
-        .returns(parentClassName)
+        .returns(parentClassName.copy(nullable = true))
         .apply {
           addCode("return when (value) {\\n⇥")
           message.constants().forEach { constant ->
             addCode("%L -> %L\\n", constant.tag, nameAllocator[constant])
           }
-          addCode("else -> throw IllegalArgumentException(%P)", "Unexpected value: \\$value")
+          addCode("else -> null")
           addCode("\\n⇤}\\n") // close the block
         }
         .build()
@@ -1175,7 +1175,7 @@ class KotlinGenerator private constructor(
         .addFunction(FunSpec.builder("fromValue")
             .addModifiers(OVERRIDE)
             .addParameter(valueName, Int::class)
-            .returns(parentClassName)
+            .returns(parentClassName.copy(nullable = true))
             .addStatement("return %T.fromValue(value)", parentClassName)
             .build())
         .build()
diff --git a/wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinGeneratorTest.kt b/wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinGeneratorTest.kt
index cdf9ad00a..8b6c87fc7 100644
--- a/wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinGeneratorTest.kt
+++ b/wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinGeneratorTest.kt
@@ -49,6 +49,7 @@ class KotlinGeneratorTest {
     assertTrue(code.contains("PhoneNumber::class"))
     assertTrue(code.contains("override fun encode(writer: ProtoWriter, value: Person)"))
     assertTrue(code.contains("enum class PhoneType(    override val value: Int  ) : WireEnum"))
+    assertTrue(code.contains("fun fromValue(value: Int): PhoneType?"))
     assertTrue(code.contains("WORK(1),"))
   }
 
diff --git a/wire-moshi-adapter/src/test/java/com/squareup/wire/protos/geology/javainteropkotlin/Period.kt b/wire-moshi-adapter/src/test/java/com/squareup/wire/protos/geology/javainteropkotlin/Period.kt
index a9020269d..595433734 100644
--- a/wire-moshi-adapter/src/test/java/com/squareup/wire/protos/geology/javainteropkotlin/Period.kt
+++ b/wire-moshi-adapter/src/test/java/com/squareup/wire/protos/geology/javainteropkotlin/Period.kt
@@ -32,15 +32,15 @@ enum class Period(
     val ADAPTER: ProtoAdapter<Period> = object : EnumAdapter<Period>(
       Period::class
     ) {
-      override fun fromValue(value: Int): Period = Period.fromValue(value)
+      override fun fromValue(value: Int): Period? = Period.fromValue(value)
     }
 
     @JvmStatic
-    fun fromValue(value: Int): Period = when (value) {
+    fun fromValue(value: Int): Period? = when (value) {
       1 -> CRETACEOUS
       2 -> JURASSIC
       3 -> TRIASSIC
-      else -> throw IllegalArgumentException("""Unexpected value: $value""")
+      else -> null
     }
   }
 }
diff --git a/wire-moshi-adapter/src/test/java/com/squareup/wire/protos/geology/kotlin/Period.kt b/wire-moshi-adapter/src/test/java/com/squareup/wire/protos/geology/kotlin/Period.kt
index 17f7c031f..f65473ac3 100644
--- a/wire-moshi-adapter/src/test/java/com/squareup/wire/protos/geology/kotlin/Period.kt
+++ b/wire-moshi-adapter/src/test/java/com/squareup/wire/protos/geology/kotlin/Period.kt
@@ -32,15 +32,15 @@ enum class Period(
     val ADAPTER: ProtoAdapter<Period> = object : EnumAdapter<Period>(
       Period::class
     ) {
-      override fun fromValue(value: Int): Period = Period.fromValue(value)
+      override fun fromValue(value: Int): Period? = Period.fromValue(value)
     }
 
     @JvmStatic
-    fun fromValue(value: Int): Period = when (value) {
+    fun fromValue(value: Int): Period? = when (value) {
       1 -> CRETACEOUS
       2 -> JURASSIC
       3 -> TRIASSIC
-      else -> throw IllegalArgumentException("""Unexpected value: $value""")
+      else -> null
     }
   }
 }
diff --git a/wire-moshi-adapter/src/test/java/com/squareup/wire/protos/person/javainteropkotlin/Person.kt b/wire-moshi-adapter/src/test/java/com/squareup/wire/protos/person/javainteropkotlin/Person.kt
index be9cde5f2..ea04406ef 100644
--- a/wire-moshi-adapter/src/test/java/com/squareup/wire/protos/person/javainteropkotlin/Person.kt
+++ b/wire-moshi-adapter/src/test/java/com/squareup/wire/protos/person/javainteropkotlin/Person.kt
@@ -244,15 +244,15 @@ class Person(
       val ADAPTER: ProtoAdapter<PhoneType> = object : EnumAdapter<PhoneType>(
         PhoneType::class
       ) {
-        override fun fromValue(value: Int): PhoneType = PhoneType.fromValue(value)
+        override fun fromValue(value: Int): PhoneType? = PhoneType.fromValue(value)
       }
 
       @JvmStatic
-      fun fromValue(value: Int): PhoneType = when (value) {
+      fun fromValue(value: Int): PhoneType? = when (value) {
         0 -> MOBILE
         1 -> HOME
         2 -> WORK
-        else -> throw IllegalArgumentException("""Unexpected value: $value""")
+        else -> null
       }
     }
   }
diff --git a/wire-moshi-adapter/src/test/java/com/squareup/wire/protos/person/kotlin/Person.kt b/wire-moshi-adapter/src/test/java/com/squareup/wire/protos/person/kotlin/Person.kt
index a28a9f0ab..11973387b 100644
--- a/wire-moshi-adapter/src/test/java/com/squareup/wire/protos/person/kotlin/Person.kt
+++ b/wire-moshi-adapter/src/test/java/com/squareup/wire/protos/person/kotlin/Person.kt
@@ -184,15 +184,15 @@ class Person(
       val ADAPTER: ProtoAdapter<PhoneType> = object : EnumAdapter<PhoneType>(
         PhoneType::class
       ) {
-        override fun fromValue(value: Int): PhoneType = PhoneType.fromValue(value)
+        override fun fromValue(value: Int): PhoneType? = PhoneType.fromValue(value)
       }
 
       @JvmStatic
-      fun fromValue(value: Int): PhoneType = when (value) {
+      fun fromValue(value: Int): PhoneType? = when (value) {
         0 -> MOBILE
         1 -> HOME
         2 -> WORK
-        else -> throw IllegalArgumentException("""Unexpected value: $value""")
+        else -> null
       }
     }
   }
diff --git a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/DeprecatedEnum.kt b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/DeprecatedEnum.kt
index 358e617b1..d2b0be5e0 100644
--- a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/DeprecatedEnum.kt
+++ b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/DeprecatedEnum.kt
@@ -28,16 +28,16 @@ enum class DeprecatedEnum(
     val ADAPTER: ProtoAdapter<DeprecatedEnum> = object : EnumAdapter<DeprecatedEnum>(
       DeprecatedEnum::class
     ) {
-      override fun fromValue(value: Int): DeprecatedEnum = DeprecatedEnum.fromValue(value)
+      override fun fromValue(value: Int): DeprecatedEnum? = DeprecatedEnum.fromValue(value)
     }
 
     @JvmStatic
-    fun fromValue(value: Int): DeprecatedEnum = when (value) {
+    fun fromValue(value: Int): DeprecatedEnum? = when (value) {
       1 -> DISABLED
       2 -> ENABLED
       3 -> ON
       4 -> OFF
-      else -> throw IllegalArgumentException("""Unexpected value: $value""")
+      else -> null
     }
   }
 }
diff --git a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/MessageWithStatus.kt b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/MessageWithStatus.kt
index a2e83bc3d..a68cf2848 100644
--- a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/MessageWithStatus.kt
+++ b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/MessageWithStatus.kt
@@ -79,13 +79,13 @@ class MessageWithStatus(
       val ADAPTER: ProtoAdapter<Status> = object : EnumAdapter<Status>(
         Status::class
       ) {
-        override fun fromValue(value: Int): Status = Status.fromValue(value)
+        override fun fromValue(value: Int): Status? = Status.fromValue(value)
       }
 
       @JvmStatic
-      fun fromValue(value: Int): Status = when (value) {
+      fun fromValue(value: Int): Status? = when (value) {
         1 -> A
-        else -> throw IllegalArgumentException("""Unexpected value: $value""")
+        else -> null
       }
     }
   }
diff --git a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/OptionalEnumUser.kt b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/OptionalEnumUser.kt
index 553d9f627..0467f3645 100644
--- a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/OptionalEnumUser.kt
+++ b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/OptionalEnumUser.kt
@@ -110,14 +110,14 @@ class OptionalEnumUser(
       val ADAPTER: ProtoAdapter<OptionalEnum> = object : EnumAdapter<OptionalEnum>(
         OptionalEnum::class
       ) {
-        override fun fromValue(value: Int): OptionalEnum = OptionalEnum.fromValue(value)
+        override fun fromValue(value: Int): OptionalEnum? = OptionalEnum.fromValue(value)
       }
 
       @JvmStatic
-      fun fromValue(value: Int): OptionalEnum = when (value) {
+      fun fromValue(value: Int): OptionalEnum? = when (value) {
         1 -> FOO
         2 -> BAR
-        else -> throw IllegalArgumentException("""Unexpected value: $value""")
+        else -> null
       }
     }
   }
diff --git a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/OtherMessageWithStatus.kt b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/OtherMessageWithStatus.kt
index 7e01fa55b..9d9762397 100644
--- a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/OtherMessageWithStatus.kt
+++ b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/OtherMessageWithStatus.kt
@@ -80,13 +80,13 @@ class OtherMessageWithStatus(
       val ADAPTER: ProtoAdapter<Status> = object : EnumAdapter<Status>(
         Status::class
       ) {
-        override fun fromValue(value: Int): Status = Status.fromValue(value)
+        override fun fromValue(value: Int): Status? = Status.fromValue(value)
       }
 
       @JvmStatic
-      fun fromValue(value: Int): Status = when (value) {
+      fun fromValue(value: Int): Status? = when (value) {
         1 -> A
-        else -> throw IllegalArgumentException("""Unexpected value: $value""")
+        else -> null
       }
     }
   }
diff --git a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt
index 405811ce6..abf7cad39 100644
--- a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt
+++ b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt
@@ -2206,13 +2206,13 @@ class AllTypes(
       val ADAPTER: ProtoAdapter<NestedEnum> = object : EnumAdapter<NestedEnum>(
         NestedEnum::class
       ) {
-        override fun fromValue(value: Int): NestedEnum = NestedEnum.fromValue(value)
+        override fun fromValue(value: Int): NestedEnum? = NestedEnum.fromValue(value)
       }
 
       @JvmStatic
-      fun fromValue(value: Int): NestedEnum = when (value) {
+      fun fromValue(value: Int): NestedEnum? = when (value) {
         1 -> A
-        else -> throw IllegalArgumentException("""Unexpected value: $value""")
+        else -> null
       }
     }
   }
diff --git a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/foreign/ForeignEnum.kt b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/foreign/ForeignEnum.kt
index 61a939ce2..a03cfc468 100644
--- a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/foreign/ForeignEnum.kt
+++ b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/foreign/ForeignEnum.kt
@@ -21,14 +21,14 @@ enum class ForeignEnum(
     val ADAPTER: ProtoAdapter<ForeignEnum> = object : EnumAdapter<ForeignEnum>(
       ForeignEnum::class
     ) {
-      override fun fromValue(value: Int): ForeignEnum = ForeignEnum.fromValue(value)
+      override fun fromValue(value: Int): ForeignEnum? = ForeignEnum.fromValue(value)
     }
 
     @JvmStatic
-    fun fromValue(value: Int): ForeignEnum = when (value) {
+    fun fromValue(value: Int): ForeignEnum? = when (value) {
       0 -> BAV
       1 -> BAX
-      else -> throw IllegalArgumentException("""Unexpected value: $value""")
+      else -> null
     }
   }
 }
diff --git a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/person/Person.kt b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/person/Person.kt
index f42b65a48..f6d6dc128 100644
--- a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/person/Person.kt
+++ b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/person/Person.kt
@@ -184,15 +184,15 @@ class Person(
       val ADAPTER: ProtoAdapter<PhoneType> = object : EnumAdapter<PhoneType>(
         PhoneType::class
       ) {
-        override fun fromValue(value: Int): PhoneType = PhoneType.fromValue(value)
+        override fun fromValue(value: Int): PhoneType? = PhoneType.fromValue(value)
       }
 
       @JvmStatic
-      fun fromValue(value: Int): PhoneType = when (value) {
+      fun fromValue(value: Int): PhoneType? = when (value) {
         0 -> MOBILE
         1 -> HOME
         2 -> WORK
-        else -> throw IllegalArgumentException("""Unexpected value: $value""")
+        else -> null
       }
     }
   }
diff --git a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/simple/SimpleMessage.kt b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/simple/SimpleMessage.kt
index fa596d68b..b5c9efad8 100644
--- a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/simple/SimpleMessage.kt
+++ b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/simple/SimpleMessage.kt
@@ -410,16 +410,16 @@ class SimpleMessage(
       val ADAPTER: ProtoAdapter<NestedEnum> = object : EnumAdapter<NestedEnum>(
         NestedEnum::class
       ) {
-        override fun fromValue(value: Int): NestedEnum = NestedEnum.fromValue(value)
+        override fun fromValue(value: Int): NestedEnum? = NestedEnum.fromValue(value)
       }
 
       @JvmStatic
-      fun fromValue(value: Int): NestedEnum = when (value) {
+      fun fromValue(value: Int): NestedEnum? = when (value) {
         1 -> FOO
         2 -> BAR
         3 -> BAZ
         3 -> BUZ
-        else -> throw IllegalArgumentException("""Unexpected value: $value""")
+        else -> null
       }
     }
   }
diff --git a/wire-tests/src/jvmKotlinAndroidTest/proto-kotlin/com/squareup/wire/protos/kotlin/person/Person.kt b/wire-tests/src/jvmKotlinAndroidTest/proto-kotlin/com/squareup/wire/protos/kotlin/person/Person.kt
index 944415ea0..e00282aaf 100644
--- a/wire-tests/src/jvmKotlinAndroidTest/proto-kotlin/com/squareup/wire/protos/kotlin/person/Person.kt
+++ b/wire-tests/src/jvmKotlinAndroidTest/proto-kotlin/com/squareup/wire/protos/kotlin/person/Person.kt
@@ -188,15 +188,15 @@ class Person(
       val ADAPTER: ProtoAdapter<PhoneType> = object : EnumAdapter<PhoneType>(
         PhoneType::class
       ) {
-        override fun fromValue(value: Int): PhoneType = PhoneType.fromValue(value)
+        override fun fromValue(value: Int): PhoneType? = PhoneType.fromValue(value)
       }
 
       @JvmStatic
-      fun fromValue(value: Int): PhoneType = when (value) {
+      fun fromValue(value: Int): PhoneType? = when (value) {
         0 -> MOBILE
         1 -> HOME
         2 -> WORK
-        else -> throw IllegalArgumentException("""Unexpected value: $value""")
+        else -> null
       }
     }
   }
diff --git a/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/MessageWithStatus.kt b/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/MessageWithStatus.kt
index b15397d27..cf8350467 100644
--- a/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/MessageWithStatus.kt
+++ b/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/MessageWithStatus.kt
@@ -81,13 +81,13 @@ class MessageWithStatus(
       val ADAPTER: ProtoAdapter<Status> = object : EnumAdapter<Status>(
         Status::class
       ) {
-        override fun fromValue(value: Int): Status = Status.fromValue(value)
+        override fun fromValue(value: Int): Status? = Status.fromValue(value)
       }
 
       @JvmStatic
-      fun fromValue(value: Int): Status = when (value) {
+      fun fromValue(value: Int): Status? = when (value) {
         1 -> A
-        else -> throw IllegalArgumentException("""Unexpected value: $value""")
+        else -> null
       }
     }
   }
diff --git a/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/OtherMessageWithStatus.kt b/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/OtherMessageWithStatus.kt
index 1ccf2bdf8..38b762575 100644
--- a/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/OtherMessageWithStatus.kt
+++ b/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/OtherMessageWithStatus.kt
@@ -82,13 +82,13 @@ class OtherMessageWithStatus(
       val ADAPTER: ProtoAdapter<Status> = object : EnumAdapter<Status>(
         Status::class
       ) {
-        override fun fromValue(value: Int): Status = Status.fromValue(value)
+        override fun fromValue(value: Int): Status? = Status.fromValue(value)
       }
 
       @JvmStatic
-      fun fromValue(value: Int): Status = when (value) {
+      fun fromValue(value: Int): Status? = when (value) {
         1 -> A
-        else -> throw IllegalArgumentException("""Unexpected value: $value""")
+        else -> null
       }
     }
   }
diff --git a/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt b/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt
index 9d1721a11..7a920678c 100644
--- a/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt
+++ b/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt
@@ -3780,13 +3780,13 @@ class AllTypes(
       val ADAPTER: ProtoAdapter<NestedEnum> = object : EnumAdapter<NestedEnum>(
         NestedEnum::class
       ) {
-        override fun fromValue(value: Int): NestedEnum = NestedEnum.fromValue(value)
+        override fun fromValue(value: Int): NestedEnum? = NestedEnum.fromValue(value)
       }
 
       @JvmStatic
-      fun fromValue(value: Int): NestedEnum = when (value) {
+      fun fromValue(value: Int): NestedEnum? = when (value) {
         1 -> A
-        else -> throw IllegalArgumentException("""Unexpected value: $value""")
+        else -> null
       }
     }
   }
diff --git a/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/person/Person.kt b/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/person/Person.kt
index 5ec51e9ab..66abddff0 100644
--- a/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/person/Person.kt
+++ b/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/person/Person.kt
@@ -244,15 +244,15 @@ class Person(
       val ADAPTER: ProtoAdapter<PhoneType> = object : EnumAdapter<PhoneType>(
         PhoneType::class
       ) {
-        override fun fromValue(value: Int): PhoneType = PhoneType.fromValue(value)
+        override fun fromValue(value: Int): PhoneType? = PhoneType.fromValue(value)
       }
 
       @JvmStatic
-      fun fromValue(value: Int): PhoneType = when (value) {
+      fun fromValue(value: Int): PhoneType? = when (value) {
         0 -> MOBILE
         1 -> HOME
         2 -> WORK
-        else -> throw IllegalArgumentException("""Unexpected value: $value""")
+        else -> null
       }
     }
   }