Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 92f2658

Browse files
committed
Java: Fix mixed tabs/spaces in qhelp examples.
1 parent b38effd commit 92f2658

15 files changed

Lines changed: 206 additions & 206 deletions

File tree

java/ql/src/Frameworks/Spring/Architecture/Refactoring Opportunities/TooManyBeans.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<beans>
2-
<!--Compose configuration files by using the 'import' element.-->
2+
<!--Compose configuration files by using the 'import' element.-->
33
<import resource="services.xml"/>
44
<import resource="resources/messageSource.xml"/>
55

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!--AVOID: Using autowiring makes it difficult to see the dependencies of the bean-->
22
<bean id="autoWiredOrderService"
3-
class="documentation.examples.spring.OrderService"
4-
autowire="byName"/>
3+
class="documentation.examples.spring.OrderService"
4+
autowire="byName"/>
55

66
<!--GOOD: Explicitly specifying the properties of the bean documents its dependencies
77
and makes the bean configuration easier to maintain-->
88
<bean id="orderService"
9-
class="documentation.examples.spring.OrderService">
10-
<property name="DAO">
11-
<idref bean="dao"/>
12-
</property>
13-
</bean>
9+
class="documentation.examples.spring.OrderService">
10+
<property name="DAO">
11+
<idref bean="dao"/>
12+
</property>
13+
</bean>
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!--AVOID: Using explicit constructor indices makes the bean configuration
22
vulnerable to changes to the constructor-->
33
<bean id="billingService1" class="documentation.examples.spring.BillingService">
4-
<constructor-arg index="0" value="John Doe"/>
5-
<constructor-arg index="1" ref="dao"/>
4+
<constructor-arg index="0" value="John Doe"/>
5+
<constructor-arg index="1" ref="dao"/>
66
</bean>
77

88
<!--GOOD: Using type matching makes the bean configuration more robust to changes in
99
the constructor-->
1010
<bean id="billingService2" class="documentation.examples.spring.BillingService">
11-
<constructor-arg ref="dao"/>
12-
<constructor-arg type="java.lang.String" value="Jane Doe"/>
13-
</bean>
11+
<constructor-arg ref="dao"/>
12+
<constructor-arg type="java.lang.String" value="Jane Doe"/>
13+
</bean>

java/ql/src/Likely Bugs/Arithmetic/BadAbsOfRandom.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
public static void main(String args[]) {
2-
Random r = new Random();
2+
Random r = new Random();
33

4-
// BAD: 'mayBeNegativeInt' is negative if
5-
// 'nextInt()' returns 'Integer.MIN_VALUE'.
6-
int mayBeNegativeInt = Math.abs(r.nextInt());
4+
// BAD: 'mayBeNegativeInt' is negative if
5+
// 'nextInt()' returns 'Integer.MIN_VALUE'.
6+
int mayBeNegativeInt = Math.abs(r.nextInt());
77

8-
// GOOD: 'nonNegativeInt' is always a value between 0 (inclusive)
9-
// and Integer.MAX_VALUE (exclusive).
10-
int nonNegativeInt = r.nextInt(Integer.MAX_VALUE);
8+
// GOOD: 'nonNegativeInt' is always a value between 0 (inclusive)
9+
// and Integer.MAX_VALUE (exclusive).
10+
int nonNegativeInt = r.nextInt(Integer.MAX_VALUE);
1111

1212
// GOOD: When 'nextInt' returns a negative number increment the returned value.
1313
int nextInt = r.nextInt();

java/ql/src/Likely Bugs/Comparison/CovariantEquals.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
class BadPoint {
2-
int x;
3-
int y;
2+
int x;
3+
int y;
44

5-
BadPoint(int x, int y) {
6-
this.x = x;
7-
this.y = y;
8-
}
5+
BadPoint(int x, int y) {
6+
this.x = x;
7+
this.y = y;
8+
}
99

10-
// overloaded equals method -- should be avoided
11-
public boolean equals(BadPoint q) {
12-
return x == q.x && y == q.y;
13-
}
10+
// overloaded equals method -- should be avoided
11+
public boolean equals(BadPoint q) {
12+
return x == q.x && y == q.y;
13+
}
1414
}
1515

1616
BadPoint p = new BadPoint(1, 2);
1717
Object q = new BadPoint(1, 2);
1818
boolean badEquals = p.equals(q); // evaluates to false
1919

2020
class GoodPoint {
21-
int x;
22-
int y;
21+
int x;
22+
int y;
2323

24-
GoodPoint(int x, int y) {
25-
this.x = x;
26-
this.y = y;
27-
}
24+
GoodPoint(int x, int y) {
25+
this.x = x;
26+
this.y = y;
27+
}
2828

29-
// correctly overrides Object.equals(Object)
30-
public boolean equals(Object obj) {
29+
// correctly overrides Object.equals(Object)
30+
public boolean equals(Object obj) {
3131
if (obj != null && getClass() == obj.getClass()) {
3232
GoodPoint q = (GoodPoint)obj;
3333
return x == q.x && y == q.y;
3434
}
3535
return false;
36-
}
36+
}
3737
}
3838

3939
GoodPoint r = new GoodPoint(1, 2);
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
public class DefineEqualsWhenAddingFields {
2-
static class Square {
3-
protected int width = 0;
4-
public Square(int width) {
5-
this.width = width;
6-
}
2+
static class Square {
3+
protected int width = 0;
4+
public Square(int width) {
5+
this.width = width;
6+
}
77
@Override
8-
public boolean equals(Object thatO) { // This method works only for squares.
9-
if(thatO != null && getClass() == thatO.getClass() ) {
8+
public boolean equals(Object thatO) { // This method works only for squares.
9+
if(thatO != null && getClass() == thatO.getClass() ) {
1010
Square that = (Square)thatO;
1111
return width == that.width;
12-
}
12+
}
1313
return false;
14-
}
15-
}
14+
}
15+
}
1616

17-
static class Rectangle extends Square {
18-
private int height = 0;
19-
public Rectangle(int width, int height) {
20-
super(width);
21-
this.height = height;
22-
}
23-
}
17+
static class Rectangle extends Square {
18+
private int height = 0;
19+
public Rectangle(int width, int height) {
20+
super(width);
21+
this.height = height;
22+
}
23+
}
2424

25-
public static void main(String[] args) {
26-
Rectangle r1 = new Rectangle(4, 3);
27-
Rectangle r2 = new Rectangle(4, 5);
28-
System.out.println(r1.equals(r2)); // Outputs 'true'
29-
}
25+
public static void main(String[] args) {
26+
Rectangle r1 = new Rectangle(4, 3);
27+
Rectangle r2 = new Rectangle(4, 5);
28+
System.out.println(r1.equals(r2)); // Outputs 'true'
29+
}
3030
}

java/ql/src/Likely Bugs/Comparison/EqualsUsesInstanceOf.java

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
11
class BadPoint {
2-
int x;
3-
int y;
2+
int x;
3+
int y;
44

5-
BadPoint(int x, int y) {
6-
this.x = x;
7-
this.y = y;
8-
}
5+
BadPoint(int x, int y) {
6+
this.x = x;
7+
this.y = y;
8+
}
99

10-
public boolean equals(Object o) {
11-
if(!(o instanceof BadPoint))
12-
return false;
13-
BadPoint q = (BadPoint)o;
14-
return x == q.x && y == q.y;
15-
}
10+
public boolean equals(Object o) {
11+
if(!(o instanceof BadPoint))
12+
return false;
13+
BadPoint q = (BadPoint)o;
14+
return x == q.x && y == q.y;
15+
}
1616
}
1717

1818
class BadPointExt extends BadPoint {
19-
String s;
19+
String s;
2020

21-
BadPointExt(int x, int y, String s) {
22-
super(x, y);
23-
this.s = s;
24-
}
21+
BadPointExt(int x, int y, String s) {
22+
super(x, y);
23+
this.s = s;
24+
}
2525

26-
// violates symmetry of equals contract
27-
public boolean equals(Object o) {
28-
if(!(o instanceof BadPointExt)) return false;
29-
BadPointExt q = (BadPointExt)o;
30-
return super.equals(o) && (q.s==null ? s==null : q.s.equals(s));
31-
}
26+
// violates symmetry of equals contract
27+
public boolean equals(Object o) {
28+
if(!(o instanceof BadPointExt)) return false;
29+
BadPointExt q = (BadPointExt)o;
30+
return super.equals(o) && (q.s==null ? s==null : q.s.equals(s));
31+
}
3232
}
3333

3434
class GoodPoint {
35-
int x;
36-
int y;
35+
int x;
36+
int y;
3737

38-
GoodPoint(int x, int y) {
39-
this.x = x;
40-
this.y = y;
41-
}
38+
GoodPoint(int x, int y) {
39+
this.x = x;
40+
this.y = y;
41+
}
4242

43-
public boolean equals(Object o) {
43+
public boolean equals(Object o) {
4444
if (o != null && getClass() == o.getClass()) {
4545
GoodPoint q = (GoodPoint)o;
4646
return x == q.x && y == q.y;
4747
}
4848
return false;
49-
}
49+
}
5050
}
5151

5252
class GoodPointExt extends GoodPoint {
53-
String s;
53+
String s;
5454

55-
GoodPointExt(int x, int y, String s) {
56-
super(x, y);
57-
this.s = s;
58-
}
55+
GoodPointExt(int x, int y, String s) {
56+
super(x, y);
57+
this.s = s;
58+
}
5959

60-
public boolean equals(Object o) {
60+
public boolean equals(Object o) {
6161
if (o != null && getClass() == o.getClass()) {
6262
GoodPointExt q = (GoodPointExt)o;
6363
return super.equals(o) && (q.s==null ? s==null : q.s.equals(s));
64-
}
65-
return false;
66-
}
64+
}
65+
return false;
66+
}
6767
}
6868

6969
BadPoint p = new BadPoint(1, 2);

java/ql/src/Likely Bugs/Comparison/HashedButNoHash.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ class Point {
88
}
99

1010
public boolean equals(Object o) {
11-
if (!(o instanceof Point)) return false;
12-
Point q = (Point)o;
13-
return x == q.x && y == q.y;
11+
if (!(o instanceof Point)) return false;
12+
Point q = (Point)o;
13+
return x == q.x && y == q.y;
1414
}
1515

16-
// Implement hashCode so that equivalent points (with the same values of x and y) have the
17-
// same hash code
16+
// Implement hashCode so that equivalent points (with the same values of x and y) have the
17+
// same hash code
1818
public int hashCode() {
19-
int hash = 7;
20-
hash = 31*hash + x;
21-
hash = 31*hash + y;
22-
return hash;
19+
int hash = 7;
20+
hash = 31*hash + x;
21+
hash = 31*hash + y;
22+
return hash;
2323
}
24-
}
24+
}
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
class LocalCache {
2-
private Collection<NativeResource> localResources;
3-
4-
//...
5-
6-
protected void finalize() throws Throwable {
7-
for (NativeResource r : localResources) {
8-
r.dispose();
9-
}
10-
};
2+
private Collection<NativeResource> localResources;
3+
4+
//...
5+
6+
protected void finalize() throws Throwable {
7+
for (NativeResource r : localResources) {
8+
r.dispose();
9+
}
10+
};
1111
}
1212

1313
class WrongCache extends LocalCache {
14-
//...
15-
@Override
16-
protected void finalize() throws Throwable {
17-
// BAD: Empty 'finalize', which does not call 'super.finalize'.
18-
// Native resources in LocalCache are not disposed of.
19-
}
14+
//...
15+
@Override
16+
protected void finalize() throws Throwable {
17+
// BAD: Empty 'finalize', which does not call 'super.finalize'.
18+
// Native resources in LocalCache are not disposed of.
19+
}
2020
}
2121

2222
class RightCache extends LocalCache {
23-
//...
24-
@Override
25-
protected void finalize() throws Throwable {
26-
// GOOD: 'finalize' calls 'super.finalize'.
23+
//...
24+
@Override
25+
protected void finalize() throws Throwable {
26+
// GOOD: 'finalize' calls 'super.finalize'.
2727
// Native resources in LocalCache are disposed of.
28-
super.finalize();
29-
}
30-
}
28+
super.finalize();
29+
}
30+
}

java/ql/src/Likely Bugs/Likely Typos/ContainerSizeCmpZero.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
class ContainerSizeCmpZero
44
{
55
private static File MakeFile(String filename) {
6-
if(filename != null && filename.length() >= 0) {
7-
return new File(filename);
8-
}
9-
return new File("default.name");
6+
if(filename != null && filename.length() >= 0) {
7+
return new File(filename);
8+
}
9+
return new File("default.name");
1010
}
1111
}

0 commit comments

Comments
 (0)