forked from spotbugs/spotbugs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21277fe
commit 014046a
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
spotbugsTestCases/src/java/constructorthrow/ConstructorThrowNegativeTest14.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package constructorthrow; | ||
|
||
/** | ||
* The Exception is thrown before the java.lang.Object constructor exits, so this is compliant, since in this case | ||
* the JVM will not execute an object's finalizer. | ||
* @see <a href="https://github.com/spotbugs/spotbugs/issues/2710">GitHub issue</a> | ||
*/ | ||
public class ConstructorThrowNegativeTest14 { | ||
public ConstructorThrowNegativeTest14() { | ||
this(verify()); | ||
} | ||
|
||
private ConstructorThrowNegativeTest14(boolean secure) { | ||
// secure is always true | ||
// Constructor without any checks | ||
} | ||
|
||
private static boolean verify() { | ||
// Returns true if data entered is valid, else throws an Exception | ||
// Assume that the attacker just enters invalid data, so this method always throws the exception | ||
throw new RuntimeException("Invalid data!"); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
spotbugsTestCases/src/java/constructorthrow/ConstructorThrowNegativeTest15.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package constructorthrow; | ||
|
||
/** | ||
* The isInitialized flag set by the constructor, and the exception is thrown by not the constructor depending on its value. | ||
*/ | ||
public class ConstructorThrowNegativeTest15 { | ||
private volatile boolean isInitialized = false; | ||
|
||
public ConstructorThrowNegativeTest15() { | ||
if (!verify()) { | ||
return; | ||
} | ||
|
||
this.isInitialized = true; | ||
} | ||
|
||
private boolean verify() { | ||
return false; | ||
} | ||
|
||
public void doSomething () { | ||
if (!this.isInitialized) { | ||
throw new RuntimeException(); | ||
} | ||
// do something | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
spotbugsTestCases/src/java/constructorthrow/ConstructorThrowTest17.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package constructorthrow; | ||
|
||
/** | ||
* The constructor throws an Exception conditionally. | ||
*/ | ||
public class ConstructorThrowTest17 { | ||
public ConstructorThrowTest17() { | ||
if (!verify()) { | ||
throw new RuntimeException(); | ||
} | ||
} | ||
|
||
private boolean verify() { | ||
return false; | ||
} | ||
} |