Skip to content

Commit a3db858

Browse files
authored
Merge pull request #1179 from smowton/smowton/feature/well_known_globals_non_null
Mark well-known globals System.out and System.err non-null
2 parents bb66937 + 89d6799 commit a3db858

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed
497 Bytes
Binary file not shown.

regression/cbmc-java/basic1/helloworld.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
/* Hello World Java Program */
55
class helloworld {
66
public static void main(String[] args) {
7+
assert(System.out != null);
78
System.out.println("Hello World!");
9+
assert(System.err != null);
10+
System.err.println("Hello World!");
11+
assert(System.in != null);
12+
try {
13+
int avail = System.in.available();
14+
}
15+
catch(java.io.IOException e) {}
816
}
917
}
10-

src/java_bytecode/java_entry_point.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Author: Daniel Kroening, [email protected]
99

1010
#include <algorithm>
1111
#include <set>
12+
#include <unordered_set>
1213
#include <iostream>
1314

1415
#include <util/arith_tools.h>
@@ -62,7 +63,6 @@ static void create_initialize(symbol_tablet &symbol_table)
6263
throw "failed to add "+std::string(INITIALIZE);
6364
}
6465

65-
6666
static bool should_init_symbol(const symbolt &sym)
6767
{
6868
if(sym.type.id()!=ID_code &&
@@ -75,6 +75,17 @@ static bool should_init_symbol(const symbolt &sym)
7575
return is_java_string_literal_id(sym.name);
7676
}
7777

78+
static bool is_non_null_library_global(const irep_idt &symbolid)
79+
{
80+
static const std::unordered_set<irep_idt, irep_id_hash> non_null_globals=
81+
{
82+
"java::java.lang.System.out",
83+
"java::java.lang.System.err",
84+
"java::java.lang.System.in"
85+
};
86+
return non_null_globals.count(symbolid);
87+
}
88+
7889
void java_static_lifetime_init(
7990
symbol_tablet &symbol_table,
8091
const source_locationt &source_location,
@@ -111,6 +122,8 @@ void java_static_lifetime_init(
111122
allow_null=false;
112123
if(allow_null && is_java_string_literal_id(nameid))
113124
allow_null=false;
125+
if(allow_null && is_non_null_library_global(nameid))
126+
allow_null=false;
114127
}
115128
auto newsym=object_factory(
116129
sym.type,

0 commit comments

Comments
 (0)