-
Notifications
You must be signed in to change notification settings - Fork 136
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
[Compiler] VerifyError for record whose canonical constructor unconditionally throws exception #487
Comments
And for the one from
Stack trace that generates the
On the stack trace, I see
Possibly the fix is as simple as changing the addition order:
|
The following code results in generating instructions after an athrow byte code statement: record X(String s) { X { throw new RuntimeException(); } } This is due to CompactConstructorDeclaration.checkAndGenerateFieldAssignment() appending field assignments after the record constructor body. This change adjusts CompactConstructorDeclaration to not generate field assignments if the execution flow is unreachable or dead after adding the statements from the record constructor. This prevents generating code after an athrow statement in the byte code. Fixes: eclipse-jdt#487 Signed-off-by: Simeon Andreev <[email protected]>
The following code results in generating instructions after an athrow byte code statement: record X(String s) { X { throw new RuntimeException(); } } This is due to CompactConstructorDeclaration.checkAndGenerateFieldAssignment() appending field assignments after the record constructor body. This change adjusts CompactConstructorDeclaration to not generate field assignments if the execution flow is unreachable or dead after adding the statements from the record constructor. This prevents generating code after an athrow statement in the byte code. Fixes: eclipse-jdt#487 Signed-off-by: Simeon Andreev <[email protected]>
The following code results in generating instructions after an athrow byte code statement: record X(String s) { X { throw new RuntimeException(); } } This is due to CompactConstructorDeclaration.checkAndGenerateFieldAssignment() appending field assignments after the record constructor body. This change adjusts CompactConstructorDeclaration to not generate field assignments if the execution flow is unreachable or dead after adding the statements from the record constructor. This prevents generating code after an athrow statement in the byte code. Fixes: eclipse-jdt#487 Signed-off-by: Simeon Andreev <[email protected]>
That would probably violate the language specification:
The question would be whether that difference is really noticeable, but there might be contrived cases, such as leaking Either way, since you did not chose this approach for your pull request it does not matter much. |
Thanks for the hint! |
The following code results in generating instructions after an athrow byte code statement: record X(String s) { X { throw new RuntimeException(); } } This is due to CompactConstructorDeclaration.checkAndGenerateFieldAssignment() appending field assignments after the record constructor body. This change adjusts CompactConstructorDeclaration to not generate field assignments if the execution flow is unreachable or dead after adding the statements from the record constructor. This prevents generating code after an athrow statement in the byte code. Fixes: eclipse-jdt#487 Signed-off-by: Simeon Andreev <[email protected]>
The following code results in generating instructions after an athrow byte code statement: record X(String s) { X { throw new RuntimeException(); } } This is due to CompactConstructorDeclaration.checkAndGenerateFieldAssignment() appending field assignments after the record constructor body. This change adjusts CompactConstructorDeclaration to not generate field assignments if the execution flow is unreachable or dead after adding the statements from the record constructor. This prevents generating code after an athrow statement in the byte code. Fixes: #487 Signed-off-by: Simeon Andreev <[email protected]>
The following code results in generating instructions after an athrow byte code statement: record X(String s) { X { throw new RuntimeException(); } } This is due to CompactConstructorDeclaration.checkAndGenerateFieldAssignment() appending field assignments after the record constructor body. This change adjusts CompactConstructorDeclaration to not generate field assignments if the execution flow is unreachable or dead after adding the statements from the record constructor. This prevents generating code after an athrow statement in the byte code. Fixes: eclipse-jdt#487 Signed-off-by: Simeon Andreev <[email protected]>
Version
Eclipse Compiler 3.31.0
(Maven:
org.eclipse.jdt:ecj:3.31.0
)Description
The Eclipse compiler seems to produce invalid byte code for a record class with at least one component whose canonical constructor unconditionally throws an exception:
I am not very familiar with Java byte code, but I assume the issue is that the compiler generates unreachable default code which tries to assign the record component fields.
javap
output:This is a quite contrived case, but it should probably nonetheless produce valid Java byte code.
This issue also occurs when the
throw
statement is wrapped withif (true) { ... }
.Reproduction steps
RecordTest.java
with the following contentVerifyError
The text was updated successfully, but these errors were encountered: