Skip to content

Store the final status of fields in componentt #2976

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 2 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions jbmc/unit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ SRC += java_bytecode/ci_lazy_methods/lazy_load_lambdas.cpp \
java_bytecode/java_bytecode_parser/parse_java_annotations.cpp \
java_bytecode/java_bytecode_parser/parse_java_attributes.cpp \
java_bytecode/java_bytecode_parser/parse_java_class.cpp \
java_bytecode/java_bytecode_parser/parse_java_field.cpp \
java_bytecode/java_object_factory/gen_nondet_string_init.cpp \
java_bytecode/java_replace_nondet/replace_nondet.cpp \
java_bytecode/java_string_library_preprocess/convert_exprt_to_string_exprt.cpp \
Expand Down
Binary file not shown.
10 changes: 10 additions & 0 deletions jbmc/unit/java_bytecode/java_bytecode_parser/ClassWithFields.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

class ClassWithFields {
final boolean final1 = true;
final Boolean final2 = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 I'd have probably picked different accessibility and/or different ways of setting them (i.e. in the constructor). You might also like to add tests for fields that hide inherited fields

final Object final3 = null;

boolean nonFinal1 = true;
Boolean nonFinal2 = false;
Object nonFinal3 = null;
}
41 changes: 41 additions & 0 deletions jbmc/unit/java_bytecode/java_bytecode_parser/parse_java_field.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*******************************************************************\
Module: Unit tests for converting fields
Author: Diffblue Ltd.
\*******************************************************************/

#include <java-testing-utils/load_java_class.h>
#include <java_bytecode/java_bytecode_convert_class.h>
#include <java_bytecode/java_bytecode_parse_tree.h>
#include <java_bytecode/java_types.h>
#include <testing-utils/catch.hpp>

SCENARIO(
"java_bytecode_parse_field",
"[core][java_bytecode][java_bytecode_parser]")
{
GIVEN("Some class with final and non final fields")
{
const symbol_tablet &symbol_table = load_java_class(
"ClassWithFields", "./java_bytecode/java_bytecode_parser");

WHEN("Parsing the class file structure")
{
THEN("The the final status of the classes fields should be correct.")
{
const symbolt &class_symbol =
symbol_table.lookup_ref("java::ClassWithFields");
const java_class_typet &java_class =
to_java_class_type(class_symbol.type);
REQUIRE(java_class.get_component("final1").get_is_final());
REQUIRE(java_class.get_component("final2").get_is_final());
REQUIRE(java_class.get_component("final3").get_is_final());
REQUIRE(!java_class.get_component("nonFinal1").get_is_final());
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ Prefer REQUIRE_FALSE

REQUIRE(!java_class.get_component("nonFinal1").get_is_final());
REQUIRE(!java_class.get_component("nonFinal1").get_is_final());
}
}
}
}