Skip to content
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

checker for returnValue and contructor super call and auto add #69

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

dufoli
Copy link
Contributor

@dufoli dufoli commented Dec 19, 2020

fix #67
fix #65

@dufoli dufoli marked this pull request as ready for review December 20, 2020 11:01
@dufoli
Copy link
Contributor Author

dufoli commented Dec 20, 2020

Hello, code is ready with PR. I have just a doubt about impact of the classCreator close.


Else it is mostly store and load return handle so no impact because it call visitor ...

@dufoli
Copy link
Contributor Author

dufoli commented Dec 20, 2020

I ma thinking to split isValid to isMissingReturnValue and isMissingSuper or this call in ctor.
To auto add call to object one by default:

            ctor.invokeSpecialMethod(
                    MethodDescriptor.ofConstructor("java.lang.Object"),
                    ctor.getThis());

wdyt ?


@Override
public AnnotationVisitor visitAnnotationDefault() {
return new DummyVisitor();
Copy link

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

current code do not handle it :
AnnotationUtils.visitAnnotationValue do not check if first param is null.
But you are right asm standard said that it can return null if no visitor is needed.
Other solution is to return null and check it in

if (value.getClass().isArray()) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gsmet @stuartwdouglas I provide 2 solutions for that. current code with dummy visitor or return null and handle it in AnnotationUtils. What do you prefer ?
Anyway, I need a full review before going further.

@dufoli dufoli changed the title start to implement test of returnValue checker for returnValue and contructor super call and auto add Dec 21, 2020
@dufoli
Copy link
Contributor Author

dufoli commented Jan 11, 2021

@gsmet @stuartwdouglas @Sanne can you review it ?

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.TypePath;

public class MethodCheckerVisitor extends MethodVisitor {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this done as a visitor, rather than just checking that the bytecode is valid when it is generated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

imagine you have a code with

public int myfunct(boolean foo, boolean bar) {
 if (foo) return 1
else if (bar) return 0;
else
throw new RuntimeException();
}

so you have 2 branchs of return to check indeed.
My first think was to check that last operation was a return and it failed because of that.
You have the exception case too...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you can not check just the methodMody, you have to enter in operation to check them.
Or you mean that I check generated code instead of AST ?

Base automatically changed from master to main March 12, 2021 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Try to detect when missing a call to returnValue Simplify creating constructors
3 participants