-
Notifications
You must be signed in to change notification settings - Fork 49
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
base: develop
Are you sure you want to change the base?
Conversation
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. What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
Signed the CLA |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
I looked at the build from travis: it seems broken for long time, but on maven specification
So not related to this pull request. |
There was a problem hiding this 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> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems unrelated to Java6
There was a problem hiding this comment.
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}); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I correct this PR as your review. |
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 |
@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? |
…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.
Create 1.3.1 version
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).
4d15bf9
to
cecead2
Compare
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. ℹ️ Googlers: Go here for more info. |
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?) 😄 |
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