mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Java: Performance tweaks
This commit is contained in:
@@ -21,5 +21,5 @@ where
|
||||
not f.isStatic() or
|
||||
not f.getType().hasName("long")
|
||||
) and
|
||||
f.getDeclaringType().getASupertype+() instanceof TypeSerializable
|
||||
f.getDeclaringType().getAStrictAncestor() instanceof TypeSerializable
|
||||
select f, "serialVersionUID should be final, static, and of type long."
|
||||
|
||||
@@ -29,7 +29,7 @@ predicate sortedCollectionBaseType(RefType t) {
|
||||
}
|
||||
|
||||
predicate sortedCollectionType(RefType t) {
|
||||
sortedCollectionBaseType(t.getASupertype*().getSourceDeclaration())
|
||||
sortedCollectionBaseType(t.getAnAncestor().getSourceDeclaration())
|
||||
}
|
||||
|
||||
string nameFor(Class c) {
|
||||
|
||||
@@ -29,7 +29,7 @@ predicate serializableOrExternalizable(Interface interface) {
|
||||
predicate collectionOrMapType(RefType t) { t instanceof CollectionType or t instanceof MapType }
|
||||
|
||||
predicate serializableType(RefType t) {
|
||||
exists(RefType sup | sup = t.getASupertype*() | serializableOrExternalizable(sup))
|
||||
exists(RefType sup | sup = t.getAnAncestor() | serializableOrExternalizable(sup))
|
||||
or
|
||||
// Collection interfaces are not serializable, but their implementations are
|
||||
// likely to be.
|
||||
@@ -77,7 +77,7 @@ predicate exceptions(Class c, Field f) {
|
||||
f.isStatic()
|
||||
or
|
||||
// Classes that implement `Externalizable` completely take over control during serialization.
|
||||
externalizable(c.getASupertype+())
|
||||
externalizable(c.getAStrictAncestor())
|
||||
or
|
||||
// Stateless session beans are not normally serialized during their usual life-cycle
|
||||
// but are forced by their expected supertype to be serializable.
|
||||
@@ -92,7 +92,7 @@ predicate exceptions(Class c, Field f) {
|
||||
from Class c, Field f, string reason
|
||||
where
|
||||
c.fromSource() and
|
||||
c.getASupertype+() instanceof TypeSerializable and
|
||||
c.getAStrictAncestor() instanceof TypeSerializable and
|
||||
f.getDeclaringType() = c and
|
||||
not exceptions(c, f) and
|
||||
reason = nonSerialReason(f.getType())
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
import java
|
||||
import semmle.code.java.JDKAnnotations
|
||||
|
||||
predicate isSerializable(RefType t) { t.getASupertype*() instanceof TypeSerializable }
|
||||
predicate isSerializable(RefType t) { t.getAnAncestor() instanceof TypeSerializable }
|
||||
|
||||
predicate withinStaticContext(NestedClass c) {
|
||||
c.isStatic() or
|
||||
|
||||
Reference in New Issue
Block a user