Java: Performance tweaks

This commit is contained in:
Ian Lynagh
2022-02-08 14:53:05 +00:00
parent 83bba47fdb
commit 7ce9b160d0
116 changed files with 266 additions and 244 deletions

View File

@@ -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."

View File

@@ -29,7 +29,7 @@ predicate sortedCollectionBaseType(RefType t) {
}
predicate sortedCollectionType(RefType t) {
sortedCollectionBaseType(t.getASupertype*().getSourceDeclaration())
sortedCollectionBaseType(t.getAnAncestor().getSourceDeclaration())
}
string nameFor(Class c) {

View File

@@ -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())

View File

@@ -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