Skip to content

Fix for crashing lambdas in a package [TG-2478] #1983

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
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/lambda3/LambdaTest/Lamb1.class
Binary file not shown.
Binary file not shown.
16 changes: 16 additions & 0 deletions regression/cbmc-java/lambda3/LambdaTest/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package LambdaTest;

interface Lamb1 {
public Integer lambFunc1(Integer x);
}

class Test {

public static Integer recvLambda(Integer y, Integer z) {
Lamb1 lmb1 = (x) -> x = y + z; // Initializing in a lambda statement
if (lmb1 != null && z != null) {
return lmb1.lambFunc1(y);
}
return lmb1.lambFunc1(z);
}
}
8 changes: 8 additions & 0 deletions regression/cbmc-java/lambda3/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
LambdaTest/Test.class
--show-symbol-table --function LambdaTest.Test.recvLambda
^EXIT=0$
^SIGNAL=0$
--
--
This is to verify that parsing lambdas in a package does not crash.
8 changes: 6 additions & 2 deletions src/java_bytecode/java_bytecode_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1777,9 +1777,13 @@ java_bytecode_parsert::parse_method_handle(const method_handle_infot &entry)
const name_and_type_infot &name_and_type =
ref_entry.get_name_and_type(pool_entry_lambda);

std::string class_name = class_entry.get_name(pool_entry_lambda);
Copy link
Contributor

Choose a reason for hiding this comment

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

would you mind adding an example here what happens here and why this is required?

Copy link
Author

Choose a reason for hiding this comment

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

Do the comments below this line make it a bit clearer perhaps? We need to replace dots by dollars (formatting for inner classes) and then slashes by dots (formatting for packages).

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, it's ok, I was just wondering about the $ in lambda function names, so I wondered whether we are sure here not to replace those.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that's a good point. They are not being replaced here, only the class name is manipulated, the lambda name is appended to the string afterwards.

// replace '.' for '$' (inner classes)
std::replace(class_name.begin(), class_name.end(), '.', '$');
// replace '/' for '.' (package)
std::replace(class_name.begin(), class_name.end(), '/', '.');
const std::string method_ref =
class_entry.get_name(pool_entry_lambda) + "." +
name_and_type.get_name(pool_entry_lambda) + ':' +
class_name + "." + name_and_type.get_name(pool_entry_lambda) + ':' +
name_and_type.get_descriptor(pool_entry_lambda);

lambda_method_handlet lambda_method_handle;
Expand Down