Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

NonAtomicVolatileUpdate misses volatile increments and decrements with parenthesized operands

Abierto Apto para principiantes
#6,214 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
java
Área
testing-qa

Línea de trabajo

Empieza con la comprobación NonAtomicVolatileUpdate e inspecciona cómo reconoce los operandos de incremento y decremento. El issue señala ASTHelpers.stripParentheses como una posible forma de manejar operandos entre paréntesis. Añade cobertura para incrementos y decrementos entre paréntesis de campos volátiles int y long, y confirma que ambas formas producen cuatro hallazgos.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Error Prone version

Error Prone 2.49.0 (javac 21.0.8, --source/--target 21)

Affected checks

NonAtomicVolatileUpdate

Description

Adding redundant parentheses around the operand of an increment or decrement causes NonAtomicVolatileUpdate to miss non-atomic updates of volatile fields. For example, (x)++ performs the same read-modify-write as x++, but only the latter is reported. The same issue occurs with decrement operations and with both int and long fields in the reproducer.

Per JLS §15.8.5, parentheses around an expression do not change its value, type, or constant-expression status. The two forms should therefore produce the same findings.

I verified the following pair on Error Prone 2.49.0:

Check Rewrite BEFORE AFTER Effect
NonAtomicVolatileUpdate x++ → (x)++ (also y++, x--, and y--) 4 0 false negative

The matcher appears to inspect the increment/decrement operand without looking through ParenthesizedTree. A possible fix is to unwrap the operand before matching it, for example with ASTHelpers.stripParentheses.

Reproducers
NonAtomicVolatileUpdate — (x)++ is missed

(x)++ is the same non-atomic read-modify-write of a volatile field as x++.

// BEFORE — 4 findings
public class Vol {
  volatile int x;
  volatile long y;
  void bad() { x++; y++; x--; y--; }
}
// AFTER — 0 findings
public class Vol {
  volatile int x;
  volatile long y;
  void bad() { (x)++; (y)++; (x)--; (y)--; }
}
Expected behavior

Both versions should produce 4 NonAtomicVolatileUpdate findings, one for each increment or decrement of a volatile field. Redundant parentheses do not make these updates atomic.

Actual behavior

The BEFORE version produces 4 findings. The AFTER version produces 0 findings, missing all four non-atomic volatile updates after their operands are parenthesized.

Lenguaje dominante
Java
Estrellas
7.3k
Forks
827
Merge medio
21 h 35 min
PR fusionados (30 d)
60

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de google/error-prone

Todos los issues de google/error-prone

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.