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

fixes a bug of ClassFile#renameClass(), some imports could not be successfully renamed. #278

Merged
merged 2 commits into from
May 10, 2022

Conversation

ximsfei
Copy link
Contributor

@ximsfei ximsfei commented Oct 8, 2019

I found two cases that failed to rename the class name:

  • case 1:
    SignatureAttribute: Generics descriptor could not be successfully renamed; Lcom/squareup/wire/TagMap<Lcom/squareup/wire/MessageAdapter$FieldInfo;>;

  • case 2:
    AnnotationDefaultAttribute: It has not been renamed.

package com.test.member.value;

import com.squareup.wire.Message;

public @interface TestMemberValue {
    Message.Datatype type() default Message.Datatype.MESSAGE;

    Message.Label[] labels() default {Message.Label.OPTIONAL, Message.Label.PACKED};

    Class<?> clazz() default TestMemberValue.class;

    Class[] clazzs() default {TestMemberValue.class};
}

Note the map:

com/squareup/wire/TagMap : com/squareup/wire/test/TagMap
com/squareup/wire/MessageAdapter$FieldInfo : com/squareup/wire/test/MessageAdapter$FieldInfo
...
com/squareup/wire/** : com/squareup/wire/test/**
com/test/member/value/TestMemberValue : com/test/test/test/member/value/TestMemberValue

The problem was fixed by this pr.

@NingZhang-e
Copy link
Contributor

Please add some unit tests to make clear what the issue you have solved.

@ximsfei
Copy link
Contributor Author

ximsfei commented Oct 17, 2019

@NingZhang-e
I have added unit tests and passed local validation.
Solved this issue, when calling ClassFile#renameClass() method, some imports could not be successfully renamed.
Refer to the case of unit test:

String sig = "<T:Ljava/lang/Exception;>LPoi$Foo<Ljava/lang/String;>;LBar;LBar2;";
String res = "<T:Ljava/lang/Exception;>LPoi$Foo<Ljava/lang/String2;>;LBar;LBar2;";
changeMsig(sig, "java/lang/String", res, "java/lang/String2");
changeMsig2(sig, "java/lang/String", res, "java/lang/String2");

changeMsig("Ljava/lang/String<Ljava/lang/Object;>;", "java/lang/String",
        "Ljava/lang/String2<Ljava/lang/Object;>;", "java/lang/String2");
changeMsig2("Ljava/lang/String<Ljava/lang/Object;>;", "java/lang/String",
        "Ljava/lang/String2<Ljava/lang/Object;>;", "java/lang/String2");

When class java/lang/String is renamed to java/lang/String2, <T:Ljava/lang/Exception;>LPoi$Foo<Ljava/lang/String;>;LBar;LBar2; and Ljava/lang/String<Ljava/lang/Object;>; needs to be changed to <T:Ljava/lang/Exception;>LPoi$Foo<Ljava/lang/String2;>;LBar;LBar2; and Ljava/lang/String2<Ljava/lang/Object;>;.

@chibash @NingZhang-e Have any other questions?

@chibash chibash merged commit 01c788f into jboss-javassist:master May 10, 2022
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

Successfully merging this pull request may close these issues.

3 participants