Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added missing fail invocation in case of exception. Removed copy paste. #249

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

Closed
laptevn wants to merge 3 commits into arangodb:master from laptevn:invalid-exception-handling
Closed

Added missing fail invocation in case of exception. Removed copy paste. #249

laptevn wants to merge 3 commits into arangodb:master from laptevn:invalid-exception-handling

Conversation

Copy link

@laptevn laptevn commented Feb 17, 2019

Hi there,
This PR fixes HostHandler#fail method not invoked in case unchecked exception is generated in HostHandler#closeCurrentOnError method.
For example this exception can be generated in FallbackHostHandler#closeCurrentOnError -> HostImpl#closeOnError.

Also while fixing this I removed copy paste of exception handling.

@@ -53,7 +51,6 @@
private final HostHandler hostHandler;

public Builder(final HostHandler hostHandler) {
super();
Copy link
Author

Choose a reason for hiding this comment

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

This is redundant since basic constructor will be invoked automatically.

} catch (ArangoDBException e) {
return handleArangoDBException(e, request);
} catch (IOException e) {
throw new ArangoDBException(e);
Copy link
Author

Choose a reason for hiding this comment

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

Similar exception handling is performed on the same level for VstCommunication.
This handling is taken from HttpProtocol that doesn't take care of it now.


public abstract T execute(Request request, HostHandle hostHandle);

public T handleArangoDBException(ArangoDBException e, Request request) {
Copy link
Author

Choose a reason for hiding this comment

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

It's bad practise to use final everywhere.
Having it for classes, methods and fields is good but not for variables and parameters.
We can pass parameters only by value in Java, so there is no way to modify the value of the parameter anyway.
Having final for variable and parameter reduces number of optimizations that JIT performs. So we loose in performance in the end.

That is shortly why it's bad practise. I fixed it only in affected lines and kept others as is.

Copy link

@ataugur ataugur Mar 8, 2019
edited
Loading

Choose a reason for hiding this comment

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

Why is it bad practice to use final in method parameters ? Only reason I can think of is code clutter but if you keep the number of parameters low then it shouldn't be a big problem.

Java is pass by value yes so you don't modify the value of the outside variable but if you don't put final in method parameter you can modify the value of the copy inside the method as it is simply a method variable. In some cases declaring method parameters as final can prevent some bugs when you mistakenly use the method parameter for assignment instead of a newly declared variable. Also if you use the method parameter inside an anonymous local class then you must declare it final.

Having final parameters should lead to more optimizations on JIT because you don't have to synchronize on them or you can have them cached in the CPU registers. So final should increase the performance instead.

Copy link
Author

@laptevn laptevn Mar 8, 2019
edited
Loading

Choose a reason for hiding this comment

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

Hi @ataugur
I wrote why on a high level. It's enough to dive deeper if you'd like.
This is Java, not C++.

Further reading:

Copy link

@ataugur ataugur Mar 9, 2019

Choose a reason for hiding this comment

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

Yes I agree with you on a high level. I don't put final in front of method parameters very often either. Yet we should also give the reasoning while giving the rule.

Like for example we should give the rule as:

  • parameters and local variables should not be declared final unless it improves readability or documents an actual design decision.
  • I am not an expert in byte code and JIT but I think I know a bit about them. I commented on general compiler writing perspective and caching behavior.

Thanks for the reply.

Copy link
Author

@laptevn laptevn Mar 9, 2019

Choose a reason for hiding this comment

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

Hi @ataugur
I'm not the person who decides which rules should be used in this project :-)

I would suggest to look at a situation as is, without searching for a hidden sense.
This project is obviously written by C++ developer, not Java developer. You can see "destructors" used, "const" everywhere - these are signs of C++ guy, because these points are good for C++ and bad for Java (and any other non C++ language).

Having final parameters should lead to more optimizations on JIT because you don't have to synchronize on them or you can have them cached in the CPU registers

Do you remember happens before relation from Java memory model? It relates to optimisations that can be made with our code.
Since you mentioned it, having synchronize block limits the number of optimisations performed similar to having final used.
This is just an example from perspective of memory model, there are other cases.

Java is completely different from C++ and has only similar syntax (I worked with both heavily and know what I'm writing about). If we start using C++ practises in Java, we will have many problems and it will take lots of time to discuss each of them. So it's easier just to use Java paradigm.

Do you have merge permissions for this PR?
I'm afraid I will lose a focus some day and won't be able to help with this PR in some time, if it's not merged in a nearest future.

Copy link
Author

laptevn commented Feb 17, 2019

.travis.yml contains "mvn install -DskipTests=true"
So tests are not run during CI build by Travis. I would recommend to pay attention to this since it makes little sense to have CI build without running tests.

Copy link

OmarAyo commented Apr 26, 2019

Hi @laptevn

Many thanks for contributing. We are obliged by law to have a signed scanned copy of a Contributor License Agreement (CLA) to be able to accept pull requests to the official ArangoDB repository - even for such small changes.

We use an Apache 2 CLA for ArangoDB and its companion projects, which can be found here: https://www.arangodb.com/documents/cla.pdf
Just fill in the form, sign and send a scanned copy over to cla@arangodb.com

Thank you

Copy link
Author

laptevn commented Apr 28, 2019

Hi @OmarAyo
I don't plan to work with this repo, so paper work makes little sense for me :-)
With this message I allow you to do whatever you want with this PR (i.e. modify, merge under your name). If you still need something signed from me, feel free to remove this PR.

3 months of waiting and paper work are too much for such changes :-)

Copy link
Contributor

@OmarAyo i will add this changes into the driver
@laptevn thanks for your support

laptevn reacted with thumbs up emoji

Copy link
Collaborator

rashtao commented Nov 11, 2021

Closing as no longer relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
1 more reviewer

@ataugur ataugur ataugur left review comments

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /