Skip to content

Commit 12b5ba9

Browse files
authored
Merge pull request #4434 from smowton/smowton/cleanup/forbid-multiple-class-files
Java front-end: rule out multiple parallel instances of java_bytecode_languaget
2 parents 1b65891 + 32be85e commit 12b5ba9

File tree

14 files changed

+54
-28
lines changed

14 files changed

+54
-28
lines changed
228 Bytes
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public class A { }
2+
class B { }
228 Bytes
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
A.class
3+
B.class
4+
^Only one \.class, \.jar or \.gbf file should be directly specified on the command-line
5+
^EXIT=1$
6+
^SIGNAL=0$

jbmc/regression/jbmc/classpath-two-classes/test_incorrect.desc

Lines changed: 0 additions & 10 deletions
This file was deleted.

jbmc/regression/jbmc/classpath-two-jars/test_incorrect.desc

Lines changed: 0 additions & 11 deletions
This file was deleted.

jbmc/regression/jbmc/string_field_aliasing/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
Cart.class
3-
--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
3+
--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
44
^EXIT=10$
55
^SIGNAL=0$
66
^VERIFICATION FAILED$
228 Bytes
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public class A { }
2+
class B { }
228 Bytes
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
A.class
3+
B.class
4+
^Only one \.class, \.jar or \.gbf file should be directly specified on the command-line
5+
^EXIT=6$
6+
^SIGNAL=0$

jbmc/src/janalyzer/janalyzer_parse_options.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,17 @@ int janalyzer_parse_optionst::doit()
355355

356356
register_languages();
357357

358+
if(cmdline.args.size() > 1)
359+
{
360+
error() << "Only one .class, .jar or .gbf file should be directly "
361+
"specified on the command-line. To force loading another another class "
362+
"use '--java-load-class somepackage.SomeClass' or "
363+
"'--lazy-methods-extra-entry-point somepackage.SomeClass.method' along "
364+
"with '--classpath'"
365+
<< messaget::eom;
366+
return CPROVER_EXIT_USAGE_ERROR;
367+
}
368+
358369
goto_model =
359370
initialize_goto_model(cmdline.args, get_message_handler(), options);
360371

jbmc/src/java_bytecode/java_bytecode_language.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,15 @@ bool java_bytecode_languaget::typecheck(
645645
const std::string &)
646646
{
647647
PRECONDITION(language_options_initialized);
648+
// There are various cases in the Java front-end where pre-existing symbols
649+
// from a previous load are not handled. We just rule this case out for now;
650+
// a user wishing to ensure a particular class is loaded should use
651+
// --java-load-class (to force class-loading) or
652+
// --lazy-methods-extra-entry-point (to ensure a method body is loaded)
653+
// instead of creating two instances of the front-end.
654+
INVARIANT(
655+
symbol_table.begin() == symbol_table.end(),
656+
"the Java front-end should only be used with an empty symbol table");
648657

649658
java_internal_additions(symbol_table);
650659

jbmc/src/jbmc/jbmc_parse_options.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,23 @@ int jbmc_parse_optionst::doit()
530530
stub_objects_are_not_null =
531531
options.get_bool_option("java-assume-inputs-non-null");
532532

533+
if(cmdline.args.empty())
534+
{
535+
error() << "Please provide a program to verify" << eom;
536+
return 6;
537+
}
538+
539+
if(cmdline.args.size() != 1)
540+
{
541+
error() << "Only one .class, .jar or .gbf file should be directly "
542+
"specified on the command-line. To force loading another another class "
543+
"use '--java-load-class somepackage.SomeClass' or "
544+
"'--lazy-methods-extra-entry-point somepackage.SomeClass.method' along "
545+
"with '--classpath'"
546+
<< messaget::eom;
547+
return 6;
548+
}
549+
533550
if(!cmdline.isset("symex-driven-lazy-loading"))
534551
{
535552
std::unique_ptr<goto_modelt> goto_model_ptr;
@@ -716,12 +733,6 @@ int jbmc_parse_optionst::get_goto_program(
716733
std::unique_ptr<goto_modelt> &goto_model,
717734
const optionst &options)
718735
{
719-
if(cmdline.args.empty())
720-
{
721-
error() << "Please provide a program to verify" << eom;
722-
return 6;
723-
}
724-
725736
{
726737
lazy_goto_modelt lazy_goto_model=lazy_goto_modelt::from_handler_object(
727738
*this, options, get_message_handler());

0 commit comments

Comments
 (0)