diff --git a/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs index 6b59474f7a..b26c9513ff 100644 --- a/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs @@ -16,9 +16,6 @@ public override void WriteCodeElement(CodeMethod codeElement, LanguageWriter wri ArgumentNullException.ThrowIfNull(writer); if (codeElement.Parent is not CodeClass parentClass) throw new InvalidOperationException("the parent of a method should be a class"); - var returnType = conventions.GetTypeString(codeElement.ReturnType, codeElement); - if (codeElement.ReturnType is CodeType { TypeDefinition: CodeEnum { Flags: true }, IsCollection: false }) - returnType = $"EnumSet<{returnType}>"; var baseReturnType = conventions.GetTypeString(codeElement.ReturnType, codeElement); var finalReturnType = GetFinalReturnType(codeElement, baseReturnType); WriteMethodDocumentation(codeElement, writer, baseReturnType, finalReturnType); @@ -681,6 +678,8 @@ private void WriteSerializationMethodCall(CodeProperty otherProp, CodeMethod met private string GetFinalReturnType(CodeMethod code, string returnType) { var voidType = code.IsAsync ? "Void" : "void"; + if (code.ReturnType is CodeType { TypeDefinition: CodeEnum { Flags: true }, IsCollection: false }) + returnType = $"EnumSet<{returnType}>"; var returnTypeAsyncPrefix = code.IsAsync ? "java.util.concurrent.CompletableFuture<" : string.Empty; var returnTypeAsyncSuffix = code.IsAsync ? ">" : string.Empty; var reType = returnType.Equals("void", StringComparison.OrdinalIgnoreCase) ? voidType : returnType; diff --git a/tests/Kiota.Builder.Tests/Writers/Java/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Java/CodeMethodWriterTests.cs index 4d30e430e9..01078f7390 100644 --- a/tests/Kiota.Builder.Tests/Writers/Java/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Java/CodeMethodWriterTests.cs @@ -2074,7 +2074,7 @@ public void WritesMessageOverrideOnPrimary() Kind = CodeMethodKind.ErrorMessageOverride, ReturnType = new CodeType { - Name = "string", + Name = "String", IsNullable = false, }, IsAsync = false,