Skip to content

Commit c498c78

Browse files
Add can_load_class helper
load_class() has side effects and cannot be used for checking whether a class could be loaded. can_load_class() only affects the jar_pool.
1 parent e5233e9 commit c498c78

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

jbmc/src/java_bytecode/java_class_loader.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ static bool is_overlay_class(const java_bytecode_parse_treet::classt &c)
103103
.has_value();
104104
}
105105

106+
bool java_class_loadert::can_load_class(const irep_idt &class_name)
107+
{
108+
for(const auto &cp_entry : classpath_entries)
109+
{
110+
auto parse_tree = load_class(class_name, cp_entry);
111+
if(parse_tree.has_value())
112+
return true;
113+
}
114+
return false;
115+
}
116+
106117
/// Check through all the places class parse trees can appear and returns the
107118
/// first implementation it finds plus any overlay class implementations.
108119
/// Uses \p class_loader_limit to limit the class files that it might (directly

jbmc/src/java_bytecode/java_class_loader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class java_class_loadert : public java_class_loader_baset
4343

4444
parse_tree_with_overlayst &operator()(const irep_idt &class_name);
4545

46+
/// Checks whether \p class_name is parseable from the classpath,
47+
/// ignoring class loading limits.
48+
bool can_load_class(const irep_idt &class_name);
49+
4650
parse_tree_with_overlayst &get_parse_tree(
4751
java_class_loader_limitt &class_loader_limit,
4852
const irep_idt &class_name);

0 commit comments

Comments
 (0)