当前位置:网站首页>代码扫描工具扫出的 Arrays.asList 使用BUG
代码扫描工具扫出的 Arrays.asList 使用BUG
2022-06-22 15:23:00 【夜七天】
在使用代码扫描工具之后,发现了代码
obj.andIn("id", Arrays.asList(arr));
此处提示有BUG,BUG信息为:
Bug: int[] passed to varargs method java.util.Arrays.asList(Object[]) in com.vs.api.impl.VsMpExaminationPaperServiceImpl.changePublish(Integer, Integer)
This code passes a primitive array to a function that takes a variable number of object arguments. This creates an array of length one to hold the primitive array and passes it to the function.
Rank: Scary (7), confidence: High
Pattern: VA_PRIMITIVE_ARRAY_PASSED_TO_OBJECT_VARARG
Type: VA, Category: CORRECTNESS (Correctness)
深入了解之后才发现:
使用 new ArrayList<>(Arrays.asList(arr))方式,Arrays.asList()的输出值会传递给ArrayList的构造器,那么会创建一个引用arr数组内元素的ArrayList,因此打乱的结果不会同步到arr数组去。如果直接使用Arrays.asList(arr)的结果,则结果会同步到arr数组。导致arr数组内元素也会被打乱。
边栏推荐
猜你喜欢
![Prometheus监控之Consul监控 [consul-exporter]](/img/9e/8547b2c38143ab0e051c1cf0b04986.png)
Prometheus监控之Consul监控 [consul-exporter]

【C语言】深度剖析整型和浮点型在内存中的存储

Make the code elegant (learn debugging + code style)

SAP ABAP data dictionary tutorial se11: tables, locked objects, views, and structures-03

机器学习笔记 - HaGRID—手势识别图像数据集简介

jsp學習之(二)---------jsp脚本元素和指令

Summary of JS methods for obtaining data types

首个赛博格人陨落背后:科技与渐冻症的极限赛跑

SAP ABAP table control and example-07

2022年中国重卡智能化升级专题研究
随机推荐
3. abstract class (shape)
What is SAP ABAP? Type, ABAP full form and meaning
ABAP query tutorial in sap: sq01, sq02, sq03-017
'不敢去怀疑代码,又不得不怀疑代码'记一次网络请求超时分析
[C language] deeply analyze the relationship between pointer and array
同花顺怎么开户?网上开户安全么?
SAP script tutorial: se71, se78, SCC1, vf03, so10-013
win10的wifi断线后无法连接
NiO service multithreaded version
6.GUI(图形,填充)
Summary of safari compatibility issues
Test for API
安全信得过!天翼云数据安全管理平台通过评测
Runtime -- explore the nature of classes, objects, and classifications
3.抽象類(shape)
SAP价值流程&帮助请求流程-011
SAP ABAP 中的模块化:宏、子程序和功能模块 -04
JSP学习之开发模式
CUMT学习日记——数字图像处理考试速成笔记
Opensql and native sql-05 in SAP ABAP the purpose of this tutorial is not to teach you SQL or database concepts