Skip to content

Java front-end: rule out multiple parallel instances of java_bytecode_languaget #4434

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

Merged
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 jbmc/regression/janalyzer/too-many-args/A.class
Binary file not shown.
2 changes: 2 additions & 0 deletions jbmc/regression/janalyzer/too-many-args/A.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class A { }
class B { }
Binary file added jbmc/regression/janalyzer/too-many-args/B.class
Binary file not shown.
6 changes: 6 additions & 0 deletions jbmc/regression/janalyzer/too-many-args/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CORE
A.class
B.class
^Only one \.class, \.jar or \.gbf file should be directly specified on the command-line
^EXIT=1$
^SIGNAL=0$
10 changes: 0 additions & 10 deletions jbmc/regression/jbmc/classpath-two-classes/test_incorrect.desc

This file was deleted.

11 changes: 0 additions & 11 deletions jbmc/regression/jbmc/classpath-two-jars/test_incorrect.desc

This file was deleted.

2 changes: 1 addition & 1 deletion jbmc/regression/jbmc/string_field_aliasing/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
Cart.class
--cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --trace --java-max-vla-length 96 --java-unwind-enum-static --max-nondet-string-length 200 --unwind 4 Cart.class --function Cart.checkTax4 --string-printable
--cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --trace --java-max-vla-length 96 --java-unwind-enum-static --max-nondet-string-length 200 --unwind 4 --function Cart.checkTax4 --string-printable
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
Expand Down
Binary file added jbmc/regression/jbmc/too-many-args/A.class
Binary file not shown.
2 changes: 2 additions & 0 deletions jbmc/regression/jbmc/too-many-args/A.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class A { }
class B { }
Binary file added jbmc/regression/jbmc/too-many-args/B.class
Binary file not shown.
6 changes: 6 additions & 0 deletions jbmc/regression/jbmc/too-many-args/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CORE
A.class
B.class
^Only one \.class, \.jar or \.gbf file should be directly specified on the command-line
^EXIT=6$
^SIGNAL=0$
11 changes: 11 additions & 0 deletions jbmc/src/janalyzer/janalyzer_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,17 @@ int janalyzer_parse_optionst::doit()

register_languages();

if(cmdline.args.size() > 1)
{
error() << "Only one .class, .jar or .gbf file should be directly "
"specified on the command-line. To force loading another another class "
"use '--java-load-class somepackage.SomeClass' or "
"'--lazy-methods-extra-entry-point somepackage.SomeClass.method' along "
"with '--classpath'"
<< messaget::eom;
return CPROVER_EXIT_USAGE_ERROR;
}

goto_model =
initialize_goto_model(cmdline.args, get_message_handler(), options);

Expand Down
9 changes: 9 additions & 0 deletions jbmc/src/java_bytecode/java_bytecode_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,15 @@ bool java_bytecode_languaget::typecheck(
const std::string &)
{
PRECONDITION(language_options_initialized);
// There are various cases in the Java front-end where pre-existing symbols
// from a previous load are not handled. We just rule this case out for now;
// a user wishing to ensure a particular class is loaded should use
// --java-load-class (to force class-loading) or
// --lazy-methods-extra-entry-point (to ensure a method body is loaded)
// instead of creating two instances of the front-end.
INVARIANT(
symbol_table.begin() == symbol_table.end(),
"the Java front-end should only be used with an empty symbol table");

java_internal_additions(symbol_table);

Expand Down
23 changes: 17 additions & 6 deletions jbmc/src/jbmc/jbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,23 @@ int jbmc_parse_optionst::doit()
stub_objects_are_not_null =
options.get_bool_option("java-assume-inputs-non-null");

if(cmdline.args.empty())
{
error() << "Please provide a program to verify" << eom;
return 6;
Copy link
Member

Choose a reason for hiding this comment

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

I'd use CPROVER_EXIT_USAGE_ERROR here

}

if(cmdline.args.size() != 1)
{
error() << "Only one .class, .jar or .gbf file should be directly "
"specified on the command-line. To force loading another another class "
"use '--java-load-class somepackage.SomeClass' or "
"'--lazy-methods-extra-entry-point somepackage.SomeClass.method' along "
"with '--classpath'"
<< messaget::eom;
return 6;
Copy link
Member

Choose a reason for hiding this comment

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

I'd use CPROVER_EXIT_USAGE_ERROR here

}

if(!cmdline.isset("symex-driven-lazy-loading"))
{
std::unique_ptr<goto_modelt> goto_model_ptr;
Expand Down Expand Up @@ -716,12 +733,6 @@ int jbmc_parse_optionst::get_goto_program(
std::unique_ptr<goto_modelt> &goto_model,
const optionst &options)
{
if(cmdline.args.empty())
{
error() << "Please provide a program to verify" << eom;
return 6;
}

{
lazy_goto_modelt lazy_goto_model=lazy_goto_modelt::from_handler_object(
*this, options, get_message_handler());
Expand Down