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

Improve some code details, fix some bugs #3314

Closed
wants to merge 25 commits into from

Conversation

CodePlayer
Copy link
Contributor

@CodePlayer CodePlayer commented Jan 24, 2025

What this PR does / why we need it?

Summary of your change

  1. 基于 JDK 8 现有特性对齐代码,精简部分冗余代码( 例如:使用 StringBuilder 替代 StringBuffer、精简不必要的泛型声明、使用 Lambda 简化匿名类;使用 Class::method 简化 Lambda、减少不必要的拆箱/装箱、使用 Objects.hash+Objects.equals 简化单元测试中的JavaBean定义 )
  2. 封装并复用部分方法,减少部分重复代码
  3. 改进部分 Map集合 的迭代处理,例如:将 containsKey( key ) + get( key ) 简化为一次 get( key ) 调用( 仅限 value 不为 null 的场景),containsKey( key ) + remove( key ) 简化为一次 remove( key ) 调用。
  4. 修复 BUG [BUG] 单引号的原始值boolean无法解析进对象 #3283
  5. 使用 String.replace() 替代 String.replaceAll(),避免不必要的正则表达式处理开销。
  6. 改进 部分访问修饰符的可见性与一致性
  7. 统一使用 java.nio.charset.StandardCharsets#UTF_8 常量引用,避免 Charset.forName() 及 相关异常声明。
  8. 修正 潜在的条件分支错误,例如:com.alibaba.fastjson.util.TypeUtils#castToJavaBean(java.util.Map<java.lang.String,java.lang.Object>, java.lang.Class<T>, com.alibaba.fastjson.parser.ParserConfig)com.alibaba.fastjson2_demo.Int2Decoder#acceptField
  9. 改进部分 集合类、StringBuilder 类的初始化容量,避免中途循环遍历的多次扩容开销。

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

@wenshao
Copy link
Member

wenshao commented Jan 24, 2025

单测跑不过呢,你本地执行下mvn test试下

@CodePlayer
Copy link
Contributor Author

CodePlayer commented Jan 24, 2025

单测跑不过呢,你本地执行下mvn test试下

image

我本地是可以的。
我看了下报错的测试用例,是读取两个 zip 文件,提示 Zip invalid distances set
报错的 LargeFile2MTestJSONStreamReaderTest 我并没有改动过(只改动过文件 LargeFile2MTest 中的一行,这不会引起问题:

IOUtils.toString(zipIn, "UTF-8");
// =>
IOUtils.toString(zipIn, StandardCharsets.UTF_8)


这两个 zip 文件我也下载和本地对比了,是一模一样的。
我猜测唯一有可能的就是:

 <plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <argLine>-Dfile.encoding=UTF-8</argLine>
 <!-- 只加了上面这一行,不然 Windows 上执行单元测试,有两个case会因为中文字符乱码导致断言失败 -->
        <includes>
            <include>com/alibaba/fastjson2/**/*.java</include>
        </includes>
        <systemPropertyVariables>
            <user.timezone>Asia/Shanghai</user.timezone>
        </systemPropertyVariables>
    </configuration>
</plugin>

我现在只能先尝试,先注释掉这一行,再看看效果。

@wenshao
Copy link
Member

wenshao commented Jan 24, 2025

把问题拆开成多个PR,现在这样改的文件太多,无法Review的

@CodePlayer CodePlayer closed this Jan 24, 2025
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.

2 participants