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

Portability to Java 6 support #74

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

fredericBregier
Copy link

This framework should be able to be binary compatible with Java 6 as
Netty does.
This merge request allows minor changes to be able to be compatible.

Also it upgrades dependencies.

All changes made by @marakiis

Issue reference #73

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@fredericBregier
Copy link
Author

Signed the CLA
@marakiis Maybe you should too

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@fredericBregier
Copy link
Author

I looked at the build from travis: it seems broken for long time, but on maven specification

<packaging>bundle</packaging>

So not related to this pull request.

Copy link

@anew anew left a comment

Choose a reason for hiding this comment

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

I started reviewing this... I think this introduces quite a lot of code that is a lot cleaner and more concise in Java 8. Given that Java 6 is long past its life time, I am not sure there is good enough justification for these changes. Maybe others have different opinions, but I personally would prefer keeping it at Java 8 language level.  

<rs-api.version>2.0</rs-api.version>
<netty.version>4.1.16.Final</netty.version>
<slf4j.version>1.7.5</slf4j.version>
<rs-api.version>2.1.1</rs-api.version>
Copy link

Choose a reason for hiding this comment

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

is this related? Does Java6 support require changing the dependency versions?

Copy link
Author

Choose a reason for hiding this comment

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

Java6 does not required it, but it is the last supported version and Java6 still compatible.

@@ -53,7 +53,7 @@ public void sendString(HttpResponseStatus status, String data, HttpHeaders heade
sendStatus(status, headers);
return;
}
ByteBuf buffer = Unpooled.wrappedBuffer(StandardCharsets.UTF_8.encode(data));
ByteBuf buffer = Unpooled.wrappedBuffer(Charset.forName("UTF-8").encode(data));
Copy link

Choose a reason for hiding this comment

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

suggestion: create a static final UTF_8 and use it here. That comes closest to the current code.

Copy link
Author

Choose a reason for hiding this comment

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

Done

}
state = State.FAILED;
throw t;
throw (Exception) t;
Copy link

Choose a reason for hiding this comment

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

This is not good practice. You do not know that this is an Exception, it could be any Error, and then the cast would fail.

Copy link
Author

Choose a reason for hiding this comment

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

Indeed! I didn't see this one (and some others). Done

@@ -255,7 +254,7 @@ public synchronized void stop(long quietPeriod, long timeout, TimeUnit unit) thr
}
} catch (Throwable t) {
state = State.FAILED;
throw t;
throw (Exception) t;
Copy link

Choose a reason for hiding this comment

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

ditto

Copy link
Author

Choose a reason for hiding this comment

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

Done

KeyStore ks = KeyStore.getInstance("JKS");
ks.load(is, keyStorePassword.toCharArray());
is.close();
Copy link

Choose a reason for hiding this comment

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

this is not needed - the finally clause closes it anyway.

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -152,7 +151,8 @@ public void sendContent(HttpResponseStatus status, final BodyProducer bodyProduc
// Response with error and close the connection
sendContent(
HttpResponseStatus.INTERNAL_SERVER_ERROR,
Unpooled.copiedBuffer("Failed to determined content length. Cause: " + t.getMessage(), StandardCharsets.UTF_8),
Unpooled.copiedBuffer("Failed to determined content length. Cause: " + t.getMessage(),
Copy link

Choose a reason for hiding this comment

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

see my comment above on creating a constant

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -48,7 +48,7 @@

HttpResponse createFailureResponse() {
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, failureStatus,
Unpooled.copiedBuffer(message, StandardCharsets.UTF_8));
Unpooled.copiedBuffer(message, Charset.forName("UTF-8")));
Copy link

Choose a reason for hiding this comment

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

same here

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -149,6 +150,9 @@ public HttpResourceHandler(Iterable<? extends HttpHandler> handlers, Iterable<?
if (method.isAnnotationPresent(DELETE.class)) {
httpMethods.add(HttpMethod.DELETE);
}
if (method.isAnnotationPresent(OPTIONS.class)) {
Copy link

Choose a reason for hiding this comment

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

seems unrelated to Java6

Copy link
Author

Choose a reason for hiding this comment

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

Yes indeed, but we need to have OPTIONS support.

@@ -91,7 +91,7 @@ public String toString() {
*/
@Override
public int hashCode() {
return Objects.hash(first, second);
return Arrays.hashCode(new Object[]{first, second});
Copy link

Choose a reason for hiding this comment

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

not the most efficient way - creating an array object just for computing a hash

Copy link
Author

Choose a reason for hiding this comment

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

In fact, that is the actual code behind Objects.hash (see Javadoc that explicitely defines it).

@@ -108,6 +108,33 @@ public boolean equals(Object o) {
return false;
}
ImmutablePair<?, ?> other = (ImmutablePair<?, ?>) o;
return Objects.equals(first, other.first) && Objects.equals(second, other.second);

boolean fst;
Copy link

Choose a reason for hiding this comment

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

consider a helper method that replaces Objects.equals().

Copy link
Author

Choose a reason for hiding this comment

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

Done

@fredericBregier
Copy link
Author

I correct this PR as your review.
I unterstand that keeping Java6 compatibility is a bit "old", but we (in our project) will move to Java7 and upward next year. In the meantime, we need Java6 compatibility. We hope those changes are very small and not being too ugly.

@chtyim
Copy link
Contributor

chtyim commented Jun 19, 2019

It is better not to merge to develop branch, but rather a special branch for java 6 support only, so that we can release a special artifact for Java 6 only. In this way, it won’t affect the regular release of the Java 8 code base

@fredericBregier
Copy link
Author

@chtyim Why not... As you wish. I will wait for your guidance.

The idea is to benefit of the project and to participate as much as we can too.

Maybe we could make after another PR with only the dependencies upgrade and the add of OPTIONS on develop?

wyzhang and others added 4 commits September 19, 2019 08:37
…nce peek() implementation operates in a similar way to poll like a consumer which can lead to a multi-consumer scenario on a multi-producer-single-consumer queue, therefore getting into an infinite loop issue inside MPSC queue implementation.
This framework should be able to be binary compatible with Java 6 as
Netty does.
This merge request allows minor changes to be able to be compatible.

Also it upgrades dependencies and allows OPTION method (which was
missing).
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@fatso83
Copy link

fatso83 commented Apr 19, 2022

Time to close this perhaps seeing it is moving nowhere? Too bad about the effort involved, but guessing Fred used this locally and has since upgraded the project to Java 7 (or 17?) 😄

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.

6 participants