错误代码500 java_您是否知道Java代码中的错误搜索工具也存在错误?

错误代码500 java

The PVS-Studio development doesn’t stand still – the team is always monitoring new trends in programming and working hard on further analyzer development. The biggest feature that appeared in the analyzer is support for Java. It is a widely used one today, and it was one of the candidates when we were considering which language to choose next. The team made available the most popular ways of the analyzer integration in the build system for the users: plugins for Maven, Gradle, and IntelliJ IDEA. However, this is just the beginning – there are a lot of ideas on further improvements in this area.

PVS-Studio的发展不会停滞不前–团队一直在监视编程的新趋势,并致力于进一步的分析仪开发。 分析器中出现的最大功能是对Java的支持。 它是当今使用最广泛的一种语言,当我们考虑下一步选择哪种语言时,它就是候选语言之一。 团队为用户提供了构建系统中最流行的分析仪集成方式:Maven,Gradle和IntelliJ IDEA插件。 但是,这仅仅是开始–关于此领域的进一步改进有很多想法。

In 2018, the team was also actively working on C++ and C# analyzer development and had released a new version of the PVS-Studio. C++ (and C#) analyzer warnings were classified according to the Common Weakness Enumeration (CWE). A PVS-Studio static code analyzer has become able to classify its warnings according to MISRA C and MISRA C++ standards. It has become relevant in relation to the development of support for various embedded systems. Documentation has also undergone big changes: all improvements have been focused on writing more common and easy-to-understand instructions for working on different systems.

在2018年,该团队还积极从事C ++和C#分析器的开发,并发布了新版本的PVS-Studio 。 C ++(和C#)分析器警告根据常见弱点枚举(CWE)分类。 PVS-Studio静态代码分析器已经能够根据MISRA C和MISRA C ++标准对警告进行分类。 它与对各种嵌入式系统的支持开发有关。 文档也发生了很大的变化:所有改进都集中在编写用于在不同系统上工作的更常见且易于理解的说明。

Of course, the developers couldn’t help testing the new version of the analyzer and have checked open projects such as IntelliJ IDEA, SpotBugs, SonarQube, и SonarJava. Here are some of the examples.

当然,开发人员无法帮助测试新版本的分析仪,并检查了IntelliJ IDEA,SpotBugs,SonarQube和иSonarJava等打开的项目。 这是一些例子。

private static boolean checkSentenceCapitalization(@NotNull String value) {
  List<String> words = StringUtil.split(value, " ");
  ....
  int capitalized = 1;
  ....
  return capitalized / words.size() < 0.2; // allow reasonable amount of
                                           // capitalized words
}

The point was that the function should return true if less than 20% of the words begin with a capital letter. Actually, the check is not working, because integer division occurs. As a result of division, we can obtain only two values: 0 or 1.

关键是,如果少于20%的单词以大写字母开头,则该函数应返回true。 实际上,该检查不起作用,因为发生了整数除法。 作为除法的结果,我们只能获得两个值:0或1。

The function will return false, only if all words begin with a capital letter. In all other cases, division operation will result in 0 and the function will return true.

仅当所有单词都以大写字母开头时,该函数才会返回false。 在所有其他情况下,除法运算将得出0,并且该函数将返回true。

Here is another interesting example:

这是另一个有趣的示例:

public synchronized boolean isIdentifier(@NotNull String name,
                                         final Project project) {
  if (!StringUtil.startsWithChar(name,'\'') &&
      !StringUtil.startsWithChar(name,'\"')) {
    name = "\"" + name;
  }
  if (!StringUtil.endsWithChar(name,'"') &&
      !StringUtil.endsWithChar(name,'\"')) {
    name += "\"";
  }
 ....
}

This code fragment checks that the name is enclosed in either single or double quotation marks. If it’s not so, double quotation marks are added automatically.

此代码段检查名称是否用单引号或双引号引起来。 如果不是这样,则会自动添加双引号。

Due to a typo, the end of the name is checked only for the presence of double quotation marks. As a result, the name in single quotation marks will be processed incorrectly.

由于输入错误,仅检查名称的末尾是否包含双引号。 结果,单引号中的名称将被错误地处理。

The name

名字

‘Abcd’

'A B C D'

due to adding extra double quotes will turn into:

由于添加额外的双引号将变成:

‘Abcd'”

'A B C D'”

Read more about other errors in Java code here: https://www.viva64.com/en/b/0603/

在此处阅读有关Java代码中其他错误的更多信息: https : //www.viva64.com/en/b/0603/

Beyond all this, the PVS-Studio team made a nice New Year’s gift for those who develops open source projects. All the contributors of such projects hosted on GitHub or Bitbucket are given free usage of the static code analyzer.

除此之外,PVS-Studio团队还为开发开放源代码项目的人提供了一个不错的新年礼物。 托管在GitHub或Bitbucket上的此类项目的所有贡献者均可免费使用静态代码分析器

翻译自: https://www.thecrazyprogrammer.com/2019/01/did-you-know-that-the-bug-search-tools-in-java-code-have-bugs-too.html

错误代码500 java

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值