Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't rename a class #3014

Open
billwert opened this issue Jan 18, 2025 · 4 comments
Open

Can't rename a class #3014

billwert opened this issue Jan 18, 2025 · 4 comments

Comments

@billwert
Copy link

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
@weidongxu-microsoft
Copy link
Member

weidongxu-microsoft commented Jan 20, 2025

I guess the Ast approach won't work, as renaming the class would also involve rename the Java file (which I guess not done by the Ast API).

For the latter one, would it work if you try it a few more times on JDK 17? (we've seen some intermittent problem on finding a class during customization, not sure why though)

Loop in @alzimmermsft

@billwert
Copy link
Author

Retry loop around ClassCustomization.rename did solve the issue locally for me. I'm not closing the issue as we should fix this one way or another (put the retry inside rename?)

@weidongxu-microsoft
Copy link
Member

weidongxu-microsoft commented Jan 22, 2025

Yeah, I am not sure why it behaves this way (that the function only works after some time, or some retry).

@alzimmermsft Could it be some lag on language-server part? Maybe it need take some time to initiate its internal upon the source code?

@alzimmermsft
Copy link
Member

Yeah, I am not sure why it behaves this way (that the function only works after some time, or some retry).

@alzimmermsft Could it be some lag on language-server part? Maybe it need take some time to initiate its internal upon the source code?

That's been my thought, that this is some form of race condition going on where the server reports completion before it's ready to support further usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants