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

Boolean的get方法与is方法共存时不可预测[BUG] #1133

Closed
void-vegetable opened this issue Feb 21, 2023 · 2 comments
Closed

Boolean的get方法与is方法共存时不可预测[BUG] #1133

void-vegetable opened this issue Feb 21, 2023 · 2 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@void-vegetable
Copy link

问题描述

Boolean的get方法与is方法共存时无法预测会调用哪个方法

环境信息

  • OS信息: windows
  • JDK信息: jdk1.8
  • 版本信息:Fastjson2 2.0.23

重现步骤

以下测试用例能否通过不可预测

import com.alibaba.fastjson2.JSON;
import lombok.Data;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.fail;

public class FastJsonBooleanTest {
    @Data
    static class A {
        private Boolean success;
        public Boolean isSuccess() {
            fail();
            return null;
        }
    }

    @Test
    void test() {
        System.out.println(JSON.toJSONString(new A()));
    }
}

期待的正确结果

按照JavaBean约定,boolean对应方法以is开头,Boolean对应方法以get开头
建议忽略以is开头的Boolean方法,或明确指定这种情况下应该以哪个方法为优先

相关日志输出

image
image

附加信息

猜测获取FiledWriter时使用了并发扫描并进行了全局缓存,导致所有后续结果会以缓存结果为准

@void-vegetable void-vegetable added the bug Something isn't working label Feb 21, 2023
@wenshao wenshao added this to the 2.0.25 milestone Feb 21, 2023
wenshao added a commit that referenced this issue Feb 21, 2023
@wenshao
Copy link
Member

wenshao commented Feb 21, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.25-SNAPSHOT/
问题已修复,请帮忙用2.0.25-SNAPSHOT版本验证,2.0.25预计在3月中旬发布

@wenshao
Copy link
Member

wenshao commented Mar 12, 2023

https://github.com/alibaba/fastjson2/releases/tag/2.0.25
问题已修复,请用新版本

@wenshao wenshao closed this as completed Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants