第一期《阿里祭》已于2021年10月10日成功举办。
本次的清理目标为
easyexcel
arthas
fastjson
druid
相关讲解发布于 https://www.bilibili.com/video/BV1FR4y1J7zW
手记抄录如下。
0. 良好案例
0.1 良好的源代码引用
要点:
0.1.1. 确认原代码协议
前去源代码仓库查看LICENSE/LICENCE(.md/MD)文件,确认许可协议,选择许可协议允许的源代码引用方式
0.1.2. 对于GPL等不允许的协议的源代码
使用合法隔离技巧
0.1.3. 对于APACHE2 MIT BSD等BSD-like协议的源代码
按照license描述行事,不要违反禁忌,不要超出许可范围
BSD-like协议的一般通用禁忌:
- 篡改作者名(冒名)
- 篡改文件中的licence header(如果有)
1. easyexcel
1.1 refines
https://github.com/xenoamess-fork/easyexcel/tree/reduce_unneed_java.lang.Short_shortValue
削减一次多余的java.lang.Short#shortValue调用
https://github.com/xenoamess-fork/easyexcel/tree/reduce_unneed_indexOf
削减一次多余的java.lang.String#indexOf调用
https://github.com/xenoamess-fork/easyexcel/tree/use_Map%23computeIfAbsent
使用Map#computeIfAbsent
https://github.com/xenoamess-fork/easyexcel/tree/make_inner_class_CellFormatResultWrapper_be_static
将内部类类CellFormatResultWrapper变为内部静态类
https://github.com/xenoamess-fork/easyexcel/tree/do_not_use_String.trim().length()
不要使用String.trim().length()来判空,效率低&消耗内存高&晦涩。请使用你们从commons-lang抄来的isBlank和isNotBlank
https://github.com/xenoamess-fork/easyexcel/tree/log_with_reason_cannot_use_%7B%7D
Logger系接口,如果要传reason,message就不能使用占位
1.2 bugs
https://github.com/xenoamess-fork/easyexcel/tree/Iterable%23iterator_should_never_return_null
Iterable#iterator不应返回null
2. arthas
2.1 refines
https://github.com/xenoamess-fork/arthas/tree/refine_collection_creations
集合类创建相关优化
使用System.currentTimeMillis(),而不是new Date().getTime()
https://github.com/xenoamess-fork/arthas/tree/use_generic_on_class_NoOpHandler
对类NoOpHandler添加泛型
https://github.com/xenoamess-fork/arthas/tree/simplify_condition
简化了条件判断
https://github.com/xenoamess-fork/arthas/tree/refine_error_logs
改良了错误捕捉
https://github.com/xenoamess-fork/arthas/tree/remove_unused_imports
去除未使用的import
https://github.com/xenoamess-fork/arthas/tree/use_StringBuilder_instead_of_StringBuffer_when_can
当可以的时候,使用StringBuilder而不是StringBuffer
https://github.com/xenoamess-fork/arthas/tree/use_static_inner_class_when_can
当可以的时候,使用静态内部类
https://github.com/xenoamess-fork/arthas/tree/numeric_issues
修复了数学计算中的问题
https://github.com/xenoamess-fork/arthas/tree/collection_issues
容器使用中的其他问题
https://github.com/xenoamess-fork/arthas/tree/string_concat_in_StringBuilder_append_chain
在StringBuilder调用链中使用了String拼接
https://github.com/xenoamess-fork/arthas/tree/do_NOT_create_wrapper_type_instance_when_can
能直接使用primitive type就不要包一层包装类
https://github.com/xenoamess-fork/arthas/tree/reduce_memory_use_in_Base64Command
Base64Command中的maxSizeLimit 转为static
https://github.com/xenoamess-fork/arthas/tree/reduce_memory_waste_in_UserStatUtil
减少无意义内存浪费
https://github.com/xenoamess-fork/arthas/tree/thread_safety_bug
典型错误使用volatile案例
https://github.com/xenoamess-fork/arthas/tree/use_Arrays.fill
使用Arrays中已有的方法来提高可读性(如果可以的话)
https://github.com/xenoamess-fork/arthas/tree/String_function_shortcuts
一些写法的可读性更好,性能同等或者略好的写法
2.2 bugs
https://github.com/xenoamess-fork/arthas/tree/potential_NPE_in_ArthasBootstrap
一个NPE
https://github.com/xenoamess-fork/arthas/tree/potential_NPE_in_ArthasReflectUtils
一个NPE
https://github.com/xenoamess-fork/arthas/tree/potential_NPE_in_Base64Command
一个NPE
https://github.com/xenoamess-fork/arthas/tree/potensial_NPE_in_BasicHttpAuthenticatorHandler
一个NPE
https://github.com/xenoamess-fork/arthas/tree/potential_NPE_in_Bootstrap
一个NPE
https://github.com/xenoamess-fork/arthas/tree/potensial_NPE_in_CompletionUtils
一个NPE
https://github.com/xenoamess-fork/arthas/tree/logic_bug_in_Decompiler
一个逻辑bug
https://github.com/xenoamess-fork/arthas/tree/potential_NPE_in_PackageInternalsFinder
一个NPE
https://github.com/xenoamess-fork/arthas/tree/potential_NPE_in_RedisTunnelClusterStore
一个NPE
另,一个逻辑bug:使用HashSet作为有顺序的容器
https://github.com/xenoamess-fork/arthas/tree/potential_NPE_in_TunnelSocketFrameHandler
一个NPE
https://github.com/xenoamess-fork/arthas/tree/log_with_reason_cannot_use_%7B%7D
Logger系接口,如果要传reason,message就不能使用占位
3. fastjson
3.1 refines
https://github.com/xenoamess-fork/fastjson/tree/unreached_branch_in_ASMDeserializerFactory
删除一个不可能抵达的branch
https://github.com/xenoamess-fork/fastjson/tree/unreached_branch_in_CalendarCodec
删除一个不可能抵达的branch
(我其实挺怀疑这里他们想做创建异常捕捉 结果做脑残了……如果真是这样那么这个应该进bugs )
性能问题
https://github.com/xenoamess-fork/fastjson/tree/avoid_unneeded_hasNext_call_in_TypeUtils
削除无意义操作
https://github.com/xenoamess-fork/fastjson/tree/use_arrays.fill_to_simplify_codes
简化代码
https://github.com/xenoamess-fork/fastjson/tree/StringBuilder_refines
StringBuilder相关优化
https://github.com/xenoamess-fork/fastjson/tree/use_static_inner_class_when_can
使用静态内部类
https://github.com/xenoamess-fork/fastjson/tree/delete_Cloneable_from_JSONValidator
从JSONValidator摘除Cloneable(我实在找不出不这么做的理由)
https://github.com/xenoamess-fork/fastjson/tree/fix_javadoc
修复javadoc中的一些错误
3.2 bugs
错误类型错误,应抛出IllegalArgumentException,实际在某个特定条件下并没抛出,导致后续抛出NPE
https://github.com/xenoamess-fork/fastjson/tree/system_array_copy_to_wrong_array_in_JSONLexerBase
手残bug,传错变量了你……
4. druid
4.1 refines
https://github.com/xenoamess-fork/druid/tree/clean_unused_imports
清除无意义import
https://github.com/xenoamess-fork/druid/tree/use_StringBuilder_if_can
如果可以的话 使用StringBuilder替代StringBuffer
https://github.com/xenoamess-fork/druid/tree/remove_redunant_boxing
去除无意义装箱拆箱
https://github.com/xenoamess-fork/druid/tree/use_Objects.equals
使用Objects.equals简化代码
https://github.com/xenoamess-fork/druid/tree/merge_same_catch_blocks
合并相同的异常处理,简化代码
https://github.com/xenoamess-fork/druid/tree/use_computeIfAbsent
使用computeIfAbsent以优化性能
https://github.com/xenoamess-fork/druid/tree/use_switch_for_multiple_string_selection
使用switch进行多项String判别,以提升性能
https://github.com/xenoamess-fork/druid/tree/fix_javadocs
修复javadoc
https://github.com/xenoamess-fork/druid/tree/use_static_inner_class_when_can
当可以的时候,使用静态内部类
https://github.com/xenoamess-fork/druid/tree/use_StandardCharsets_to_avoid_forName_cost
使用StandardCharsets以去除寻找成本
https://github.com/xenoamess-fork/druid/tree/use_StringUtils.repeat
使用StringUtils.repeat
https://github.com/xenoamess-fork/druid/tree/collection_Bulk
使用容器的批量口子 提高性能
https://github.com/xenoamess-fork/druid/tree/use_print_when_no_format
没有格式的时候就不要用printf了
https://github.com/xenoamess-fork/druid/tree/delete_impossible_path_in_OrderByResolve
清理不可达代码
https://github.com/xenoamess-fork/druid/tree/delete_unused_field_Lexer.digits
清理无用的属性
https://github.com/xenoamess-fork/druid/tree/duplicated_put_in_a_same_map
map,重复赋值
https://github.com/xenoamess-fork/druid/tree/String_refines
String系优化
https://github.com/xenoamess-fork/druid/tree/unneeded_containsKey_waste
去除无意义的containsKey调用
去除不可达分支
https://github.com/xenoamess-fork/druid/tree/impossible_to_both_be_null_and_be_SQLIntegerExpr
去除不可达分支
https://github.com/xenoamess-fork/druid/tree/simplify_conditions
清理无意义判断条件
4.2 bugs
https://github.com/xenoamess-fork/druid/tree/int_overflow
多处int溢出
https://github.com/xenoamess-fork/druid/tree/setters_in_MySqlAlterTablespaceStatement_meaningless
四个无意义的废物setter函数
https://github.com/xenoamess-fork/druid/tree/confusing_getChildren_function
令人迷惑的getChildren
https://github.com/xenoamess-fork/druid/tree/another_confusing_getChildren_function
另一个令人迷惑的getChildren
https://github.com/xenoamess-fork/druid/tree/NPE_in_DruidDataSource
一个NPE
https://github.com/xenoamess-fork/druid/tree/wrong_class_SQLServerInsertStatement_casting
错误的类型转换
https://github.com/xenoamess-fork/druid/tree/NPE_in_WallFilter
一个NPE
https://github.com/xenoamess-fork/druid/tree/NClob_is_a_subclass_of_Clob
父子类择出,逻辑判断错谬
https://github.com/xenoamess-fork/druid/tree/NPE_in_SchemaStatVisitor
一个NPE
https://github.com/xenoamess-fork/druid/tree/NPE_in_SpringStatManager
一个NPE
https://github.com/xenoamess-fork/druid/tree/Float_is_not_Double_in_SQLIntegerExpr
认为Float是Double
https://github.com/xenoamess-fork/druid/tree/NPE_in_SearchModifier
一个NPE
https://github.com/xenoamess-fork/druid/tree/NPE_in_SQLShowGrantsStatement
一个NPE
不合法的equals实现
https://github.com/xenoamess-fork/druid/tree/re-implement_SQLUtils.hash
重新实现SQLUtils.hash。原方法让我感到身在动物园。
https://github.com/xenoamess-fork/druid/tree/wrong_way_to_use_Reader
经典的初学者错误使用Reader案例
https://github.com/xenoamess-fork/druid/tree/bug_in_RestoreVisitor.visit
纯bug,传错参了
https://github.com/xenoamess-fork/druid/tree/total_wrong_Schema.findFunction
完全荒谬的实现
https://github.com/xenoamess-fork/druid/tree/bug_in_ExportParameterVisitorUtils
纯bug,传错参了
https://github.com/xenoamess-fork/druid/tree/String_can_never_equals_SQLExpr
equals比较类型错谬
https://github.com/xenoamess-fork/druid/tree/SQLOpenStatement_is_subclass_of_SQLStatement
父子类择出,逻辑判断错谬
https://github.com/xenoamess-fork/druid/tree/int_cast_to_double_is_never_NaN
判断滞后bug
- 本文作者: XenoAmess
- 本文链接: http://xenoamess.com/2021/10/13/20211013阿里祭第1期纪要/
-
版权声明:
本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。