mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Java: fix javac errors in test code
This commit is contained in:
@@ -43,28 +43,28 @@ class Test {
|
||||
new Bogus().exec("Irrelevant version of exec");
|
||||
}
|
||||
|
||||
void apacheExecute1() {
|
||||
void apacheExecute1() throws IOException {
|
||||
String line = "AcroRd32.exe /p /h some.file";
|
||||
CommandLine cmdLine = CommandLine.parse(line);
|
||||
DefaultExecutor executor = new DefaultExecutor();
|
||||
int exitValue = executor.execute(cmdLine);
|
||||
}
|
||||
|
||||
void apacheExecute2() {
|
||||
void apacheExecute2() throws IOException {
|
||||
String line = "AcroRd32.exe /p /h some.file";
|
||||
CommandLine cmdLine = CommandLine.parse(line, null);
|
||||
DefaultExecutor executor = new DefaultExecutor();
|
||||
int exitValue = executor.execute(cmdLine);
|
||||
}
|
||||
|
||||
void apacheExecute3() {
|
||||
void apacheExecute3() throws IOException {
|
||||
CommandLine cmdLine = new CommandLine("AcroRd32.exe");
|
||||
cmdLine.addArguments("/p /h some.file");
|
||||
DefaultExecutor executor = new DefaultExecutor();
|
||||
int exitValue = executor.execute(cmdLine);
|
||||
}
|
||||
|
||||
void apacheExecute4() {
|
||||
void apacheExecute4() throws IOException {
|
||||
CommandLine cmdLine = new CommandLine("AcroRd32.exe");
|
||||
cmdLine.addArguments("/p /h some.file", false);
|
||||
DefaultExecutor executor = new DefaultExecutor();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Test {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws java.io.IOException {
|
||||
// Relative paths
|
||||
Runtime.getRuntime().exec("make");
|
||||
Runtime.getRuntime().exec("m");
|
||||
|
||||
@@ -88,8 +88,8 @@ public class CommentedCode {
|
||||
*   ;
|
||||
*   ;
|
||||
*/
|
||||
return -1;
|
||||
}
|
||||
|
||||
// public static int commentedOutMethod(){
|
||||
//
|
||||
// return 123;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class A {
|
||||
case 0: return p;
|
||||
case 1: return s;
|
||||
case 2: return b1.getElem();
|
||||
case 3: return b2.getElem();
|
||||
default:return b2.getElem();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.List;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
class Test {
|
||||
public static void ioutils() {
|
||||
public static void ioutils() throws java.io.FileNotFoundException, java.io.IOException {
|
||||
InputStream inp = new FileInputStream("test"); // user input
|
||||
|
||||
InputStream buf = IOUtils.buffer(inp);
|
||||
|
||||
@@ -14,7 +14,7 @@ class Test {
|
||||
return "tainted";
|
||||
}
|
||||
|
||||
public static void jacksonObjectMapper() {
|
||||
public static void jacksonObjectMapper() throws java.io.FileNotFoundException, java.io.UnsupportedEncodingException {
|
||||
String s = taint();
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
File file = new File("testFile");
|
||||
@@ -32,7 +32,7 @@ class Test {
|
||||
System.out.println(reconstructed);
|
||||
}
|
||||
|
||||
public static void jacksonObjectWriter() {
|
||||
public static void jacksonObjectWriter() throws java.io.FileNotFoundException, java.io.UnsupportedEncodingException {
|
||||
String s = taint();
|
||||
ObjectWriter ow = new ObjectWriter();
|
||||
File file = new File("testFile");
|
||||
|
||||
@@ -15,7 +15,7 @@ public class A {
|
||||
sink(b2);
|
||||
}
|
||||
|
||||
void test2() {
|
||||
void test2() throws IOException {
|
||||
ByteArrayOutputStream bOutput = new ByteArrayOutputStream();
|
||||
bOutput.write(taint());
|
||||
byte[] b = bOutput.toByteArray();
|
||||
@@ -25,11 +25,11 @@ public class A {
|
||||
sink(b2);
|
||||
}
|
||||
|
||||
void streamWrite(ByteArrayOutputStream baos, byte[] data) {
|
||||
void streamWrite(ByteArrayOutputStream baos, byte[] data) throws IOException {
|
||||
baos.write(data);
|
||||
}
|
||||
|
||||
void test3(ByteArrayOutputStream baos) {
|
||||
void test3(ByteArrayOutputStream baos) throws IOException {
|
||||
streamWrite(baos, taint());
|
||||
sink(baos.toByteArray());
|
||||
}
|
||||
@@ -38,11 +38,11 @@ public class A {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
}
|
||||
|
||||
void streamWriteHolder(BaosHolder bh, byte[] data) {
|
||||
void streamWriteHolder(BaosHolder bh, byte[] data) throws IOException {
|
||||
bh.baos.write(data);
|
||||
}
|
||||
|
||||
void test4(BaosHolder bh) {
|
||||
void test4(BaosHolder bh) throws IOException {
|
||||
streamWriteHolder(bh, taint());
|
||||
sink(bh.baos.toByteArray());
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class A {
|
||||
byte[] data = new byte[10];
|
||||
}
|
||||
|
||||
void test5_a(DataHolder dh) {
|
||||
void test5_a(DataHolder dh) throws IOException {
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(taint());
|
||||
bais.read(dh.data);
|
||||
test5_b(dh);
|
||||
|
||||
@@ -11,7 +11,7 @@ public class B {
|
||||
|
||||
public static void sink(Object o) { }
|
||||
|
||||
public static void maintest() {
|
||||
public static void maintest() throws java.io.UnsupportedEncodingException, java.net.MalformedURLException {
|
||||
String[] args = taint();
|
||||
// tainted - access to main args
|
||||
String[] aaaargs = args;
|
||||
|
||||
@@ -4,21 +4,21 @@ import android.app.Activity;
|
||||
|
||||
public class IntentSources extends Activity {
|
||||
|
||||
public void test() {
|
||||
public void test() throws java.io.IOException {
|
||||
|
||||
String trouble = this.getIntent().getStringExtra("key");
|
||||
Runtime.getRuntime().exec(trouble);
|
||||
|
||||
}
|
||||
|
||||
public void test2() {
|
||||
public void test2() throws java.io.IOException {
|
||||
|
||||
String trouble = getIntent().getStringExtra("key");
|
||||
Runtime.getRuntime().exec(trouble);
|
||||
|
||||
}
|
||||
|
||||
public void test3() {
|
||||
public void test3() throws java.io.IOException {
|
||||
|
||||
String trouble = getIntent().getExtras().getString("key");
|
||||
Runtime.getRuntime().exec(trouble);
|
||||
@@ -29,9 +29,9 @@ public class IntentSources extends Activity {
|
||||
|
||||
class OtherClass {
|
||||
|
||||
public void test(IntentSources is) {
|
||||
public void test(IntentSources is) throws java.io.IOException {
|
||||
String trouble = is.getIntent().getStringExtra("key");
|
||||
Runtime.getRuntime().exec(trouble);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,5 +4,5 @@ import java.rmi.Remote;
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
public interface RmiFlow extends Remote {
|
||||
String listDirectory(String path);
|
||||
String listDirectory(String path) throws java.io.IOException;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package security.library.dataflow;
|
||||
|
||||
public class RmiFlowImpl implements RmiFlow {
|
||||
public String listDirectory(String path) {
|
||||
public String listDirectory(String path) throws java.io.IOException {
|
||||
String command = "ls " + path;
|
||||
Runtime.getRuntime().exec(command);
|
||||
return "pretend there are some results here";
|
||||
}
|
||||
|
||||
public String notRemotable(String path) {
|
||||
public String notRemotable(String path) throws java.io.IOException {
|
||||
String command = "ls " + path;
|
||||
Runtime.getRuntime().exec(command);
|
||||
return "pretend there are some results here";
|
||||
|
||||
@@ -36,7 +36,7 @@ class ViableCallable {
|
||||
i2.f("", 0l);
|
||||
}
|
||||
|
||||
<TMock> TMock Mock() { throw new Exception(); }
|
||||
<TMock> TMock Mock() { throw new Error(); }
|
||||
|
||||
void CreateTypeInstance() {
|
||||
Run(new C2<Boolean>(), null, null, null);
|
||||
@@ -63,7 +63,7 @@ abstract class C1<T1_C1, T2_C1> {
|
||||
M(x, 8);
|
||||
}
|
||||
|
||||
public void f(T1_C1 x, T2_C1 y) { throw new Exception(); }
|
||||
public void f(T1_C1 x, T2_C1 y) { throw new Error(); }
|
||||
}
|
||||
|
||||
interface I1<T_I1> {
|
||||
@@ -80,27 +80,27 @@ interface I2<T_I2> {
|
||||
|
||||
class C2<T_C2> extends C1<String, T_C2> implements I1<T_C2> {
|
||||
@Override
|
||||
public <T3_C2> T_C2 M(String x, T3_C2 y) { throw new Exception(); }
|
||||
public <T3_C2> T_C2 M(String x, T3_C2 y) { throw new Error(); }
|
||||
}
|
||||
|
||||
class C3 extends C1<String, Long> implements I2<Long> {
|
||||
@Override
|
||||
public <T3_C3> Long M(String x, T3_C3 y) { throw new Exception(); }
|
||||
public <T3_C3> Long M(String x, T3_C3 y) { throw new Error(); }
|
||||
}
|
||||
|
||||
class C4<T_C4> extends C1<T_C4[], Boolean> {
|
||||
@Override
|
||||
public <T3_C4> Boolean M(T_C4[] x, T3_C4 y) { throw new Exception(); }
|
||||
public <T3_C4> Boolean M(T_C4[] x, T3_C4 y) { throw new Error(); }
|
||||
}
|
||||
|
||||
class C5 extends C1<String, Boolean> {
|
||||
@Override
|
||||
public <T3_C5> Boolean M(String x, T3_C5 y) { throw new Exception(); }
|
||||
public <T3_C5> Boolean M(String x, T3_C5 y) { throw new Error(); }
|
||||
}
|
||||
|
||||
class C6<T1_C6, T2_C6> extends C1<T1_C6, T2_C6> {
|
||||
@Override
|
||||
public <T3_C6> T2_C6 M(T1_C6 x, T3_C6 y) { throw new Exception(); }
|
||||
public <T3_C6> T2_C6 M(T1_C6 x, T3_C6 y) { throw new Error(); }
|
||||
|
||||
public void Run(T1_C6 x) {
|
||||
// Viable callables: C6.M(), C7.M()
|
||||
@@ -113,7 +113,7 @@ class C6<T1_C6, T2_C6> extends C1<T1_C6, T2_C6> {
|
||||
|
||||
class C7<T1_C7> extends C6<T1_C7, Byte> {
|
||||
@Override
|
||||
public <T3_C7> Byte M(T1_C7 x, T3_C7 y) { throw new Exception(); }
|
||||
public <T3_C7> Byte M(T1_C7 x, T3_C7 y) { throw new Error(); }
|
||||
|
||||
public void Run(T1_C7 x) {
|
||||
// Viable callables: C7.M()
|
||||
@@ -129,11 +129,11 @@ class C7<T1_C7> extends C6<T1_C7, Byte> {
|
||||
|
||||
class C8<T_C8, T2_C8> extends C1<String, T2_C8> {
|
||||
@Override
|
||||
public <T3_C8> T2_C8 M(String x, T3_C8 y) { throw new Exception(); }
|
||||
public <T3_C8> T2_C8 M(String x, T3_C8 y) { throw new Error(); }
|
||||
}
|
||||
|
||||
class C9<T_C9> extends C8<Boolean, Boolean> {
|
||||
@Override
|
||||
public <T3_C9> Boolean M(String x, T3_C9 y) { throw new Exception(); }
|
||||
public <T3_C9> Boolean M(String x, T3_C9 y) { throw new Error(); }
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@ class ViableCallable2 {
|
||||
}
|
||||
|
||||
class A {
|
||||
public void m() { throw new Exception(); }
|
||||
public void m() { throw new Error(); }
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
@Override
|
||||
public void m() { throw new Exception(); }
|
||||
public void m() { throw new Error(); }
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Logic {
|
||||
}
|
||||
|
||||
private static void checkTrue(boolean b, String msg) {
|
||||
if (!b) throw new Exception(msg);
|
||||
if (!b) throw new Error (msg);
|
||||
}
|
||||
|
||||
private static void checkFalse(boolean b, String msg) {
|
||||
|
||||
@@ -3,7 +3,7 @@ class Test {
|
||||
void test(int x) {
|
||||
z = 0;
|
||||
if (x < 0) {
|
||||
throw new Exception();
|
||||
throw new Error();
|
||||
}
|
||||
int y = 0;
|
||||
while(x >= 0) {
|
||||
|
||||
@@ -18,7 +18,7 @@ class PathCreation {
|
||||
File f = new File(new File("dir"), "sub");
|
||||
}
|
||||
|
||||
public void testNewFileWithURI() {
|
||||
public void testNewFileWithURI() throws java.net.URISyntaxException {
|
||||
File f = new File(new URI("dir"));
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class PathCreation {
|
||||
Path p2 = Path.of("dir", "sub");
|
||||
}
|
||||
|
||||
public void testPathOfWithURI() {
|
||||
public void testPathOfWithURI() throws java.net.URISyntaxException {
|
||||
Path p = Path.of(new URI("dir"));
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class PathCreation {
|
||||
Path p2 = Paths.get("dir", "sub");
|
||||
}
|
||||
|
||||
public void testPathsGetWithURI() {
|
||||
public void testPathsGetWithURI() throws java.net.URISyntaxException {
|
||||
Path p = Paths.get(new URI("dir"));
|
||||
}
|
||||
|
||||
@@ -53,19 +53,19 @@ class PathCreation {
|
||||
Path p = Path.of("dir").resolve("sub");
|
||||
}
|
||||
|
||||
public void testNewFileWriterWithString() {
|
||||
public void testNewFileWriterWithString() throws java.io.IOException {
|
||||
FileWriter fw = new FileWriter("dir");
|
||||
}
|
||||
|
||||
public void testNewFileReaderWithString() {
|
||||
public void testNewFileReaderWithString() throws java.io.FileNotFoundException {
|
||||
FileReader fr = new FileReader("dir");
|
||||
}
|
||||
|
||||
public void testNewFileOutputStreamWithString() {
|
||||
public void testNewFileOutputStreamWithString() throws java.io.FileNotFoundException {
|
||||
FileOutputStream fos = new FileOutputStream("dir");
|
||||
}
|
||||
|
||||
public void testNewFileInputStreamWithString() {
|
||||
public void testNewFileInputStreamWithString() throws java.io.FileNotFoundException {
|
||||
FileInputStream fis = new FileInputStream("dir");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class ReflectiveAccess {
|
||||
return classContainingAnnotation.getAnnotation(annotationClass);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
|
||||
Class<?> testClass = Class.forName("reflection.ReflectiveAccess$TestClass");
|
||||
|
||||
testClass.newInstance();
|
||||
|
||||
@@ -5,8 +5,8 @@ class TestThrow2 {
|
||||
{
|
||||
try {
|
||||
thrower();
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user