Skip to content

Commit 627e055

Browse files
Unit tests throws exceptions parsing.
1 parent a5300fa commit 627e055

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed
Binary file not shown.
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import java.io.*;
2+
3+
public class ThrowsExceptions {
4+
5+
public static void test() throws CustomException, IOException {
6+
StringReader sr = new StringReader("");
7+
sr.read();
8+
throw new CustomException();
9+
}
10+
11+
}
12+
13+
class CustomException extends Exception {
14+
}

jbmc/unit/java_bytecode/java_bytecode_parser/parse_java_attributes.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <java-testing-utils/load_java_class.h>
1010
#include <java_bytecode/java_bytecode_convert_class.h>
11+
#include <java_bytecode/java_bytecode_convert_method.h>
1112
#include <java_bytecode/java_bytecode_parse_tree.h>
1213
#include <java_bytecode/java_types.h>
1314
#include <testing-utils/catch.hpp>
@@ -596,4 +597,32 @@ SCENARIO(
596597
}
597598
}
598599
}
600+
601+
GIVEN("A method that may or may not throw exceptions")
602+
{
603+
const symbol_tablet &new_symbol_table = load_java_class(
604+
"ThrowsExceptions", "./java_bytecode/java_bytecode_parser");
605+
WHEN("Parsing the exceptions attribute for a method that throws exceptions")
606+
{
607+
THEN("We should be able to get the list of exceptions it throws")
608+
{
609+
const symbolt &class_symbol =
610+
new_symbol_table.lookup_ref("java::ThrowsExceptions");
611+
const symbolt &method_symbol =
612+
new_symbol_table.lookup_ref("java::ThrowsExceptions.test:()V");
613+
const code_typet method = to_code_type(method_symbol.type);
614+
const std::vector<irept> exceptions = method.throws_exceptions();
615+
REQUIRE(exceptions.size() == 2);
616+
REQUIRE(
617+
std::find(
618+
exceptions.begin(), exceptions.end(), irept("CustomException")) !=
619+
exceptions.end());
620+
REQUIRE(
621+
std::find(
622+
exceptions.begin(),
623+
exceptions.end(),
624+
irept("java.io.IOException")) != exceptions.end());
625+
}
626+
}
627+
}
599628
}

0 commit comments

Comments
 (0)