Skip to content
This repository was archived by the owner on Jul 6, 2026. It is now read-only.
This repository was archived by the owner on Jul 6, 2026. It is now read-only.

Can't rename a class #3014

Description

@billwert

This code:

   // name is from a for loop here.
   ClassCustomization classCustomization = customization.getPackage("com.azure.messaging.eventgrid.systemevents").getClass(name);
            classCustomization.customizeAst(comp -> {
                ClassOrInterfaceDeclaration clazz = comp.getClassByName(name).get();
                logger.info("found " + name);
                clazz.setName("Acs" + name);
            });

Fails like this:

error   | Javagen | Failed to generate code.
java.lang.RuntimeException: Failed to complete postprocessing.
        at com.microsoft.typespec.http.client.generator.core.postprocessor.Postprocessor.postProcess(Postprocessor.java:111)
        at com.microsoft.typespec.http.client.generator.core.Javagen.generateJava(Javagen.java:95)
        at com.microsoft.typespec.http.client.generator.core.Javagen.processInternal(Javagen.java:78)
        at com.microsoft.typespec.http.client.generator.core.extension.plugin.NewPlugin.process(NewPlugin.java:324)
        at com.azure.autorest.Main.lambda$main$1(Main.java:14)
        at com.microsoft.typespec.http.client.generator.core.extension.jsonrpc.Connection.lambda$dispatch$2(Connection.java:143)
        at com.microsoft.typespec.http.client.generator.core.extension.jsonrpc.Connection.lambda$process$4(Connection.java:245)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.RuntimeException: Unable to complete customization
        at com.microsoft.typespec.http.client.generator.core.postprocessor.Postprocessor.postProcess(Postprocessor.java:104)
        ... 11 more
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: MicrosoftTeamsAppIdentifier does not exist in package com.azure.messaging.eventgrid.systemevents
        at com.azure.autorest.customization.Customization.run(Customization.java:52)
        at com.microsoft.typespec.http.client.generator.core.postprocessor.Postprocessor.postProcess(Postprocessor.java:101)
        ... 11 more
Caused by: java.lang.IllegalArgumentException: MicrosoftTeamsAppIdentifier does not exist in package com.azure.messaging.eventgrid.systemevents
        at com.azure.autorest.customization.PackageCustomization.lambda$getClass$3(PackageCustomization.java:47)
        at com.azure.autorest.customization.implementation.Utils.returnIfPresentOrThrow(Utils.java:211)
        at com.azure.autorest.customization.PackageCustomization.getClass(PackageCustomization.java:45)
        at com.azure.autorest.customization.ClassCustomization.refreshSymbol(ClassCustomization.java:609)
        at com.azure.autorest.customization.ClassCustomization.customizeAst(ClassCustomization.java:605)
        at EventGridCustomization.lambda$customizeCentralCommuicationEvents$5(EventGridCustomization.java:259)
        at java.base/java.util.Arrays$ArrayList.forEach(Arrays.java:4204)
        at EventGridCustomization.customizeCentralCommuicationEvents(EventGridCustomization.java:257)
        at EventGridCustomization.customize(EventGridCustomization.java:249)
        at com.azure.autorest.customization.Customization.run(Customization.java:48)
        ... 12 more

When refreshSymbol runs after CustomizeAst is done, because the underlying type name has changed without the mechanics of the normal ClassCustomization.rename.

Unfortunately, ClassCustomization.rename as called below fails on Java 17+:

        customization
                .getPackage("com.azure.messaging.eventgrid.systemevents")
                .getClass("MicrosoftTeamsAppIdentifier")
                .rename("AcsMicrosoftTeamsAppIdentifier");

fails like this on Java 17+, but works on Java 11:

error   | Javagen | Failed to generate code.
java.lang.RuntimeException: Failed to complete postprocessing.
        at com.microsoft.typespec.http.client.generator.core.postprocessor.Postprocessor.postProcess(Postprocessor.java:111)
        at com.microsoft.typespec.http.client.generator.core.Javagen.generateJava(Javagen.java:95)
        at com.microsoft.typespec.http.client.generator.core.Javagen.processInternal(Javagen.java:78)
        at com.microsoft.typespec.http.client.generator.core.extension.plugin.NewPlugin.process(NewPlugin.java:324)
        at com.azure.autorest.Main.lambda$main$1(Main.java:14)
        at com.microsoft.typespec.http.client.generator.core.extension.jsonrpc.Connection.lambda$dispatch$2(Connection.java:143)
        at com.microsoft.typespec.http.client.generator.core.extension.jsonrpc.Connection.lambda$process$4(Connection.java:245)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.RuntimeException: Unable to complete customization
        at com.microsoft.typespec.http.client.generator.core.postprocessor.Postprocessor.postProcess(Postprocessor.java:104)
        ... 11 more
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: Renamed failed with new class AcsMicrosoftTeamsAppIdentifier not found.
        at com.azure.autorest.customization.Customization.run(Customization.java:52)
        at com.microsoft.typespec.http.client.generator.core.postprocessor.Postprocessor.postProcess(Postprocessor.java:101)
        ... 11 more
Caused by: java.lang.IllegalArgumentException: Renamed failed with new class AcsMicrosoftTeamsAppIdentifier not found.
        at com.azure.autorest.customization.ClassCustomization.rename(ClassCustomization.java:495)
        at EventGridCustomization.customizeCentralCommuicationEvents(EventGridCustomization.java:259)
        at EventGridCustomization.customize(EventGridCustomization.java:250)
        at com.azure.autorest.customization.Customization.run(Customization.java:48)
        ... 12 more

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions