Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes related to #1816 #1982

Merged
merged 5 commits into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added regression/cbmc-java/invalid_classpath/Test.class
Binary file not shown.
3 changes: 3 additions & 0 deletions regression/cbmc-java/invalid_classpath/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class Test {
public void main() {}
}
10 changes: 10 additions & 0 deletions regression/cbmc-java/invalid_classpath/test-jar.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE symex-driven-lazy-loading-expected-failure
Test.class
--classpath ./NotHere.jar
^EXIT=6$
^SIGNAL=0$
^the program has no entry point$
^failed to load class `Test'$
--
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit cryptic, so worth explaining what you're testing for and why this is the expected behaviour (perhaps in a followup PR considering the urgency)

--
symex-driven lazy loading should emit "the program has no entry point" but currently doesn't
10 changes: 10 additions & 0 deletions regression/cbmc-java/invalid_classpath/test-path.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE symex-driven-lazy-loading-expected-failure
Test.class
--classpath ./NotHere
^EXIT=6$
^SIGNAL=0$
^the program has no entry point$
^failed to load class `Test'$
--
--
symex-driven lazy loading should emit "the program has no entry point" but currently doesn't
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth raising a ticket for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smowton - have you got this covered?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package java.lang;

public class Object {
public final Class<?> getClass() {
return null;
}

public int hashCode() { return 0; }

public boolean equals(Object obj) { return (this == obj); }

protected Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
}

public String toString() { return "object"; }

public final void notify() {}

public final void notifyAll() {}

public final void wait(long timeout) throws InterruptedException {
throw new InterruptedException();
}

public final void wait(long timeout, int nanos) throws InterruptedException {
wait(timeout);
}

public final void wait() throws InterruptedException { wait(0); }

protected void finalize() throws Throwable { }
}
10 changes: 10 additions & 0 deletions regression/cbmc-java/provide_object_implementation/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE symex-driven-lazy-loading-expected-failure
java/lang/Object.class

^EXIT=6$
^SIGNAL=0$
^the program has no entry point$
--
^failed to add class symbol java::java\.lang\.Object$
--
symex-driven lazy loading should emit "the program has no entry point" but currently doesn't
6 changes: 6 additions & 0 deletions src/java_bytecode/java_bytecode_convert_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ void java_bytecode_convert_classt::operator()(
PRECONDITION(!parse_trees.empty());
const irep_idt &class_name = parse_trees.front().parsed_class.name;

if(symbol_table.has_symbol("java::" + id2string(class_name)))
{
debug() << "Skip class " << class_name << " (already loaded)" << eom;
return;
}

// Add array types to the symbol table
add_array_types(symbol_table);

Expand Down
29 changes: 17 additions & 12 deletions src/java_bytecode/java_class_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ java_class_loadert::parse_tree_with_overlayst &java_class_loadert::operator()(
optionalt<java_bytecode_parse_treet> java_class_loadert::get_class_from_jar(
const irep_idt &class_name,
const std::string &jar_file,
const jar_indext &jar_index,
java_class_loader_limitt &class_loader_limit)
{
jar_indext &jar_index = jars_by_path.at(jar_file);
auto jar_index_it = jar_index.find(class_name);
if(jar_index_it == jar_index.end())
return {};
Expand Down Expand Up @@ -112,9 +112,11 @@ java_class_loadert::get_parse_tree(
// First add all given JAR files
for(const auto &jar_file : jar_files)
{
read_jar_file(class_loader_limit, jar_file);
jar_index_optcreft index = read_jar_file(class_loader_limit, jar_file);
if(!index)
continue;
optionalt<java_bytecode_parse_treet> parse_tree =
get_class_from_jar(class_name, jar_file, class_loader_limit);
get_class_from_jar(class_name, jar_file, *index, class_loader_limit);
if(parse_tree)
parse_trees.push_back(*parse_tree);
}
Expand All @@ -130,23 +132,26 @@ java_class_loadert::get_parse_tree(

// This does not read from the jar file but from the jar_filet object we
// just created
read_jar_file(class_loader_limit, core_models);

optionalt<java_bytecode_parse_treet> parse_tree =
get_class_from_jar(class_name, core_models, class_loader_limit);
if(parse_tree)
parse_trees.push_back(*parse_tree);
jar_index_optcreft index = read_jar_file(class_loader_limit, core_models);
if(index)
{
optionalt<java_bytecode_parse_treet> parse_tree =
get_class_from_jar(class_name, core_models, *index, class_loader_limit);
if(parse_tree)
parse_trees.push_back(*parse_tree);
}
}

// Then add everything on the class path
for(const auto &cp_entry : config.java.classpath)
{
if(has_suffix(cp_entry, ".jar"))
{
read_jar_file(class_loader_limit, cp_entry);

jar_index_optcreft index = read_jar_file(class_loader_limit, cp_entry);
if(!index)
continue;
optionalt<java_bytecode_parse_treet> parse_tree =
get_class_from_jar(class_name, cp_entry, class_loader_limit);
get_class_from_jar(class_name, cp_entry, *index, class_loader_limit);
if(parse_tree)
parse_trees.push_back(*parse_tree);
}
Expand Down
1 change: 1 addition & 0 deletions src/java_bytecode/java_class_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class java_class_loadert:public messaget
optionalt<java_bytecode_parse_treet> get_class_from_jar(
const irep_idt &class_name,
const std::string &jar_file,
const jar_indext &jar_index,
java_class_loader_limitt &class_loader_limit);
};

Expand Down