-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathInefficientOutputStream.ql
40 lines (37 loc) · 1.34 KB
/
InefficientOutputStream.ql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* @name Inefficient output stream
* @description Using the default implementation of 'write(byte[],int,int)'
* provided by 'java.io.OutputStream' is very inefficient.
* @kind problem
* @problem.severity warning
* @precision very-high
* @id java/inefficient-output-stream
* @tags efficiency
*/
import java
class InefficientWriteBytes extends Class {
InefficientWriteBytes() {
this.hasQualifiedName("java.io", "OutputStream") or
this.hasQualifiedName("java.io", "FilterOutputStream")
}
}
from Class c, Method m
where
not c.isAbstract() and
not c instanceof InefficientWriteBytes and
c.getASupertype() instanceof InefficientWriteBytes and
c.getAMethod() = m and
m.getName() = "write" and
m.getNumberOfParameters() = 1 and
m.getParameterType(0).(PrimitiveType).getName() = "int" and
exists(Method m2 | c.inherits(m2) |
m2.getName() = "write" and
m2.getNumberOfParameters() = 3 and
m2.getDeclaringType() instanceof InefficientWriteBytes
) and
// If that method doesn't call write itself, then we don't have a problem.
// This is the case is some dummy implementations.
exists(MethodCall ma | ma.getEnclosingCallable() = m | ma.getMethod().getName() = "write")
select c,
"This class extends 'java.io.OutputStream' and implements $@, but does not override 'write(byte[],int,int)'.",
m, m.getName()