mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
java: fixes from the CI bots
This commit is contained in:
@@ -159,9 +159,9 @@ module Modification {
|
||||
predicate isThreadSafeType(Type t) {
|
||||
t.(RefType).getSourceDeclaration().getName().matches(["Atomic%", "Concurrent%"])
|
||||
or
|
||||
t.(RefType).getSourceDeclaration().getName() in ["ThreadLocal"]
|
||||
t.(RefType).getSourceDeclaration().getName() = "ThreadLocal"
|
||||
or
|
||||
// Anything in `java.itul.concurrent` is thread safe.
|
||||
// Anything in `java.util.concurrent` is thread safe.
|
||||
// See https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/package-summary.html#MemoryVisibility
|
||||
t.(RefType).getPackage().getName() = "java.util.concurrent"
|
||||
or
|
||||
@@ -303,7 +303,7 @@ class ClassAnnotatedAsThreadSafe extends Class {
|
||||
)
|
||||
}
|
||||
|
||||
/** Holds if `a` can be reached by a path from a public method and `e` is the expression in that method that stsarts the path. */
|
||||
/** Holds if `a` can be reached by a path from a public method and `e` is the expression in that method that starts the path. */
|
||||
predicate publicAccess(Expr e, ExposedFieldAccess a) {
|
||||
exists(Method m | m.isPublic() | this.providesAccess(m, e, a))
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ predicate isAssignedDefaultValue(Field f) {
|
||||
}
|
||||
|
||||
predicate isSafelyPublished(Field f) {
|
||||
f.isFinal() or // TODO: Consider non-primitive types
|
||||
f.isFinal() or // NOTE: For non-primitive types, 'final' alone does not guarantee safe publication unless the object is immutable or safely constructed. Consider reviewing the handling of non-primitive fields for safe publication.
|
||||
f.isStatic() or
|
||||
f.isVolatile() or
|
||||
isThreadSafeType(f.getType()) or
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// If the variable is involved in several different monitors, we get an alert for each monitor that
|
||||
// is not correctly used.
|
||||
// A single alert can have many related locations, since each conflicting access which is not
|
||||
// prpoerly synchronized is a related location.
|
||||
// properly synchronized is a related location.
|
||||
// This leads to many lines in the .expected file.
|
||||
package examples;
|
||||
|
||||
|
||||
@@ -5,14 +5,14 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
@ThreadSafe
|
||||
public class Test {
|
||||
/**
|
||||
* Escaping field due to public visuability.
|
||||
* Escaping field due to public visibility.
|
||||
*/
|
||||
int publicField;
|
||||
|
||||
private int y;
|
||||
final int immutableField = 1;
|
||||
|
||||
// As of the below examples with synchronized as well. Except the incorretly placed lock.
|
||||
// As of the below examples with synchronized as well. Except the incorrectly placed lock.
|
||||
|
||||
private Lock lock = new ReentrantLock();
|
||||
|
||||
@@ -53,7 +53,7 @@ public class Test {
|
||||
}
|
||||
|
||||
/**
|
||||
* Incorretly locks y.
|
||||
* Incorrectly locks y.
|
||||
* @param y
|
||||
*/
|
||||
public void setYWrongLock(int y) {
|
||||
|
||||
Reference in New Issue
Block a user