Примеры ошибок, обнаруженных с помощью диагностики V6007


V6007. Expression is always true/false.


IntelliJ IDEA Community Edition

V6007 [CWE-571] Expression 'i < endOffset' is always true. EnterAfterJavadocTagHandler.java 183


static Context parse(....) {
  ....
  for (int i = offset; i < endOffset; i++) {
    char c = text.charAt(i);
    if (c == '<' && i < endOffset && text.charAt(i + 1) == '/'
        && startTag != null
        && CharArrayUtil.regionMatches(text, i + 2, endOffset, startTag))
    {
      endTagStartOffset = i;
      break;
    }
  }
  ....
}

IntelliJ IDEA Community Edition

V6007 [CWE-570] Expression 'i == exampleUsages.length' is always false. IntentionDescriptionPanel.java 192


private static void showUsages(....)
{
  ....
  for (int i = 0; i < exampleUsages.length; i++) {
    final TextDescriptor exampleUsage = exampleUsages[i];
    final String name = exampleUsage.getFileName();
    final FileTypeManagerEx fileTypeManager = FileTypeManagerEx.getInstanceEx();
    final String extension = fileTypeManager.getExtension(name);
    final FileType fileType = fileTypeManager.getFileTypeByExtension(extension);

    IntentionUsagePanel usagePanel;
    if (reuse) {
      usagePanel = (IntentionUsagePanel)panel.getComponent(i);
    }
    else {
      usagePanel = new IntentionUsagePanel();
      usagePanels.add(usagePanel);
    }
    usagePanel.reset(exampleUsage.getText(), fileType);

    if (!reuse) {
      if (i == exampleUsages.length) {                        // <=
        gb.gridwidth = GridBagConstraints.REMAINDER;
      }
      panel.add(usagePanel, gb);
      gb.gridx++;
    }
  }
  ....
}

IntelliJ IDEA Community Edition

V6007 [CWE-571] Expression 'buffer.length() > 0' is always true. DeleteUtil.java 62


public static String generateWarningMessage(....)
{
  ....
  if (buffer.length() > 0) {
    if (buffer.length() > 0) {
      buffer.append(" ").append(
        IdeBundle.message("prompt.delete.and")).append(" ");
    }
  }
  ....
}

IntelliJ IDEA Community Edition

V6007 [CWE-571] Expression 'index >= 0' is always true. Updater.java 184


public int findPreviousIndex(int current) {
  int count = myPainter.getErrorStripeCount();
  int foundIndex = -1;
  int foundLayer = 0;
  if (0 <= current && current < count) {
    current--;
    for (int index = count - 1; index >= 0; index++) {        // <=
      int layer = getLayer(index);
      if (layer > foundLayer) {
        foundIndex = index;
        foundLayer = layer;
      }
    }
  ....
}

IntelliJ IDEA Community Edition

V6007 [CWE-570] Expression '"0".equals(text)' is always false. ConvertIntegerToDecimalPredicate.java 46


public boolean satisfiedBy(@NotNull PsiElement element) {
  ....
  @NonNls final String text = expression.getText().replaceAll("_", "");
  if (text == null || text.length() < 2) {
    return false;
  }
  if ("0".equals(text) || "0L".equals(text) || "0l".equals(text)) {
    return false;
  }
  return text.charAt(0) == '0';
}

SpotBugs

V6007 [CWE-571] Expression 'count < 4' is always true. Util.java 394


public static String getXMLType(@WillNotClose InputStream in) throws IOException
{
  ....
  String s;
  int count = 0;
  while (count < 4) {
    s = r.readLine();
    if (s == null) {
      break;
    }
    Matcher m = tag.matcher(s);
    if (m.find()) {
      return m.group(1);
    }
  }
  throw new IOException("Didn't find xml tag");
  ....
}

SpotBugs

V6007 [CWE-570] Expression '"remove".equals(invokedMethodName)' is always false. FindUnrelatedTypesInGenericContainer.java 618


private void analyzeMethod(....) throws .... {
  ....
  if (invokedMethodName.startsWith("contains") ||
      "remove".equals(invokedMethodName)) {
  ....
  } else if ("get".equals(invokedMethodName) ||
             "remove".equals(invokedMethodName)) {
  ....
}

Bouncy Castle

V6007 [CWE-570] Expression 'c == '\r'' is always false. PEMUtil.java 38


private String readLine(InputStream in)
  throws IOException
{
  ....
  do
  {
    while (((c = in.read()) != '\r') && c != '\n' && (c >= 0))
    {
      if (c == '\r')
      {
        continue;
      }

      l.append((char)c);
    }
  }
  while (c >= 0 && l.length() == 0);
  ....
}

Bouncy Castle

V6007 [CWE-570] Expression '(b1 | b2) < 0' is always false. ArmoredInputStream.java 76


private static final byte[] decodingTable;

private int decode(
  int      in0,
  int      in1,
  int      in2,
  int      in3,
  int[]    out)
  throws IOException
{
  int    b1, b2, b3, b4;
  ....
  b1 = decodingTable[in0] & 0xff;
  b2 = decodingTable[in1] & 0xff;

  if ((b1 | b2) < 0)
  {
    throw new IOException("invalid armor");
  }
}

Bouncy Castle

V6007 [CWE-570] Expression 'j < numPassesKPG' is always false. McElieceKobaraImaiCipherTest.java 36


public void performTest()
  throws Exception
{
  int numPassesKPG = 0;   // TODO: this algorithm is broken
  int numPassesEncDec = 10;
  Random rand = new Random();
  byte[] mBytes;
  for (int j = 0; j < numPassesKPG; j++)
  ....
}

Elasticsearch

V6007 Expression 's.charAt(i) != '\t'' is always true. Cron.java(1223)


private static int findNextWhiteSpace(int i, String s) {
  for (; i < s.length() && (s.charAt(i) != ' ' || s.charAt(i) != '\t'); i++)
  {
      // intentionally empty
  }
  return i;
}

Elasticsearch

V6007 Expression 'remaining == 0' is always false. PemUtils.java(439)


private static byte[]
generateOpenSslKey(char[] password, byte[] salt, int keyLength)
{
  ....
  int copied = 0;
  int remaining;
  while (copied < keyLength) {
    remaining = keyLength - copied;
    ....
    copied += bytesToCopy;
    if (remaining == 0) {      // <=
        break;
    }
    ....
  }
  ....
}

Elasticsearch

V6007 Expression 'healthCheckDn.indexOf('=') > 0' is always false. ActiveDirectorySessionFactory.java(73)


ActiveDirectorySessionFactory(RealmConfig config,
                              SSLService sslService,
                              ThreadPool threadPool)
                              throws LDAPException
{
  super(....,
        () -> {
          if (....) {
              final String healthCheckDn = ....;
              if (healthCheckDn.isEmpty() &&
                  healthCheckDn.indexOf('=') > 0)
              {
                  return healthCheckDn;
              }
          }
          return ....;
        },
        ....);
  ....
}

Elasticsearch

V6007 Expression '(int)x < 0' is always false. BCrypt.java(429)


private static byte char64(char x) {
  if ((int)x < 0 || (int)x > index_64.length)
    return -1;
  return index_64[(int)x];
}

CUBA Platform

V6007 Expression 'StringUtils.isNotEmpty("handleTabKey")' is always true. SourceCodeEditorLoader.java(60)


@Override
public void loadComponent() {
  ....
  String handleTabKey = element.attributeValue("handleTabKey");
  if (StringUtils.isNotEmpty("handleTabKey")) {
    resultComponent.setHandleTabKey(Boolean.parseBoolean(handleTabKey));
  }
  ....
}

Similar errors can be found in some other places:

  • V6007 Expression 'StringUtils.isNotEmpty("editable")' is always true. AbstractTableLoader.java(596)

CUBA Platform

V6007 Expression 'previousMenuItemFlatIndex >= 0' is always true. CubaSideMenuWidget.java(328)


protected MenuItemWidget findNextMenuItem(MenuItemWidget currentItem) {
  List<MenuTreeNode> menuTree = buildVisibleTree(this);
  List<MenuItemWidget> menuItemWidgets = menuTreeToList(menuTree);

  int menuItemFlatIndex = menuItemWidgets.indexOf(currentItem);
  int previousMenuItemFlatIndex = menuItemFlatIndex + 1;
  if (previousMenuItemFlatIndex >= 0) {
      return menuItemWidgets.get(previousMenuItemFlatIndex);
  }
  return null;
}

CUBA Platform

V6007 Expression 'mask.charAt(i + offset) != placeHolder' is always true. DatePickerDocument.java(238)


private String calculateFormattedString(int offset, String text) .... {
  ....
  if ((mask.charAt(i + offset) == placeHolder)) {         // <=
    ....
  } else if ((mask.charAt(i + offset) != placeHolder) &&  // <=
             (Character.isDigit(text.charAt(i)))) {
    ....
  }
  ....
}

CUBA Platform

V6007 Expression 'connector == null' is always false. HTML5Support.java(169)


private boolean validate(NativeEvent event) {
  ....
  while (connector == null) {
    widget = widget.getParent();
    connector = Util.findConnectorFor(widget);
  }

  if (this.connector == connector) {
      return true;
  } else if (connector == null) {             // <=
      return false;
  } else if (connector.getWidget() instanceof VDDHasDropHandler) {
      return false;
  }
  return true;
}

Similar errors can be found in some other places:

  • V6007 Expression 'StringUtils.isBlank(strValue)' is always true. Param.java(818)

CUBA Platform

V6007 Expression 'needReload' is always false. WebAbstractTable.java(2702)


protected boolean handleSpecificVariables(Map<String, Object> variables) {
  boolean needReload = false;

  if (isUsePresentations() && presentations != null) {
    Presentations p = getPresentations();

    if (p.getCurrent() != null && p.isAutoSave(p.getCurrent())
        && needUpdatePresentation(variables)) {
      Element e = p.getSettings(p.getCurrent());
      saveSettings(e);
      p.setSettings(p.getCurrent(), e);
    }
  }
  return needReload;
}

Apache Hive

V6007 Expression 'key.startsWith("hplsql.")' is always true. Exec.java(675)


void initOptions()
{
  ....
  if (key == null || value == null || !key.startsWith("hplsql.")) { // <=
    continue;
  }
  else if (key.compareToIgnoreCase(Conf.CONN_DEFAULT) == 0) {
    ....
  }
  else if (key.startsWith("hplsql.conn.init.")) {
    ....
  }
  else if (key.startsWith(Conf.CONN_CONVERT)) {
    ....
  }
  else if (key.startsWith("hplsql.conn.")) {
   ....
  }
  else if (key.startsWith("hplsql.")) {                            // <=
   ....
  }
}

Apache Hive

V6007 Expression 'columnNameProperty.length() == 0' is always false. OrcRecordUpdater.java(238)


private static
TypeDescription getTypeDescriptionFromTableProperties(....)
{
  ....
  if (tableProperties != null) {
    final String columnNameProperty = ....;
    final String columnTypeProperty = ....;

    if (   !Strings.isNullOrEmpty(columnNameProperty)
        && !Strings.isNullOrEmpty(columnTypeProperty))
    {
      List<String> columnNames = columnNameProperty.length() == 0
                                 ? new ArrayList<String>()
                                 : ....;

      List<TypeInfo> columnTypes = columnTypeProperty.length() == 0
                                   ? new ArrayList<TypeInfo>()
                                   : ....;
      ....
      }
    }
  }
  ....
}

Apache Hive

V6007 Expression 'colOrScalar1.equals("Column")' is always false. GenVectorCode.java(3469)


private void
generateDateTimeArithmeticIntervalYearMonth(String[] tdesc) throws Exception
{
  ....
  String colOrScalar1 = tdesc[4];
  ....
  String colOrScalar2 = tdesc[6];
  ....
  if (colOrScalar1.equals("Col") && colOrScalar1.equals("Column"))    // <=
  {
    ....
  } else if (colOrScalar1.equals("Col") && colOrScalar1.equals("Scalar"))
  {
    ....
  } else if (colOrScalar1.equals("Scalar") && colOrScalar1.equals("Column"))
  {
    ....
  }
}

Similar errors can be found in some other places:

  • V6007 Expression 'colOrScalar1.equals("Scalar")' is always false. GenVectorCode.java(3475)
  • V6007 Expression 'colOrScalar1.equals("Column")' is always false. GenVectorCode.java(3486)
  • V6007 Expression 'characters == null' is always false. RandomTypeUtil.java(43)
  • And 4 additional diagnostic messages.

Apache Dubbo

V6007 Expression 'endKey[i] < 0xff' is always true. OptionUtil.java(32)


public static final ByteSequence prefixEndOf(ByteSequence prefix) {
  byte[] endKey = prefix.getBytes().clone();
  for (int i = endKey.length - 1; i >= 0; i--) {          // <=
    if (endKey[i] < 0xff) {
      endKey[i] = (byte) (endKey[i] + 1);
      return ByteSequence.from(Arrays.copyOf(endKey, i + 1));
    }
  }
  return ByteSequence.from(NO_PREFIX_END);
}

Apache Dubbo

V6007 Expression 'isPreferIPV6Address()' is always false. NetUtils.java(236)


private static Optional<InetAddress> toValidAddress(InetAddress address) {
  if (address instanceof Inet6Address) {
    Inet6Address v6Address = (Inet6Address) address;
    if (isPreferIPV6Address()) {
      return Optional.ofNullable(normalizeV6Address(v6Address));
    }
  }
  if (isValidV4Address(address)) {
    return Optional.of(address);
  }
  return Optional.empty();
}

static boolean isPreferIPV6Address() {
  boolean preferIpv6 = Boolean.getBoolean("java.net.preferIPv6Addresses");
  if (!preferIpv6) {
    return false;     // <=
  }
  return false;       // <=
}

Apache Dubbo

V6007 Expression '!mask[i].equals(ipAddress[i])' is always true. NetUtils.java(476)


public static boolean matchIpRange(....) throws UnknownHostException {
  ....
  for (int i = 0; i < mask.length; i++) {
    if ("*".equals(mask[i]) || mask[i].equals(ipAddress[i])) {   // <=
      continue;
    } else if (mask[i].contains("-")) {
       ....
    } else if (....) {
      continue;
    } else if (!mask[i].equals(ipAddress[i])) {      // <=
      return false;
    }
  }
  return true;
}

Apache Dubbo

V6007 Expression 'message.length > 0' is always true. DeprecatedTelnetCodec.java(302)


protected Object decode(.... , byte[] message) throws IOException {
  ....
  if (message == null || message.length == 0) {         // <=
    return NEED_MORE_INPUT;
  }
  ....
  // Here the variable message doesn't change!
  ....
  if (....) {
    String value = history.get(index);
    if (value != null) {
      byte[] b1 = value.getBytes();
      if (message != null && message.length > 0) {              // <=
        byte[] b2 = new byte[b1.length + message.length];
        System.arraycopy(b1, 0, b2, 0, b1.length);
        System.arraycopy(message, 0, b2, b1.length, message.length);
        message = b2;
      } else {
        message = b1;
      }
    }
  }
  ....
}

Similar errors can be found in some other places:

  • V6007 Expression 'message != null' is always true. DeprecatedTelnetCodec.java(302)

Apache Dubbo

V6007 Expression '!shouldExport()' is always false. ServiceConfig.java(371)


public synchronized void export() {
  checkAndUpdateSubConfigs();

  if (!shouldExport()) {                                     // <=
    return;
  }

  if (shouldDelay()) {
    ....
  } else {
    doExport();
}

private boolean shouldExport() {
  Boolean export = getExport();
  // default value is true
  return export == null ? true : export;
}
....
@Override
public Boolean getExport() {
  return (export == null && provider != null) ? provider.getExport() : export;
}

protected Boolean export;
....
public Boolean getExport() {
  return export;
}
....
public void setExport(Boolean export) {
  this.export = export;
}

@Override
public void build(T instance) {
....
  if (export != null) {
    instance.setExport(export);
  }
....
}

because of the uninitialized 'export' field, the setExport method is never executed, as a result getExport always returns null, which is why !shouldExport() is always false



Найденные ошибки

Проверено проектов
361
Собрано ошибок
13 417

А ты совершаешь ошибки в коде?

Проверь с помощью
PVS-Studio

Статический анализ
кода для C, C++, C#
и Java

goto PVS-Studio;