Skip to content

Java: Ratpack HTTP Framework Additional Modeling #7007

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

Merged
merged 2 commits into from
Nov 29, 2021

Conversation

JLLeitschuh
Copy link
Contributor

Adds models for ratpack.func.Pair, and ratpack.exec.Result.
Improve models for ratpack.exec.Promise.

@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged.

Click to show differences in coverage

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    Others,"``cn.hutool.core.codec``, ``com.esotericsoftware.kryo.io``, ``com.esotericsoftware.kryo5.io``, ``com.fasterxml.jackson.core``, ``com.fasterxml.jackson.databind``, ``com.opensymphony.xwork2.ognl``, ``com.unboundid.ldap.sdk``, ``flexjson``, ``groovy.lang``, ``groovy.util``, ``jodd.json``, ``net.sf.saxon.s9api``, ``ognl``, ``org.apache.commons.codec``, ``org.apache.commons.jexl2``, ``org.apache.commons.jexl3``, ``org.apache.commons.ognl``, ``org.apache.directory.ldap.client.api``, ``org.apache.ibatis.jdbc``, ``org.apache.shiro.codec``, ``org.apache.shiro.jndi``, ``org.codehaus.groovy.control``, ``org.dom4j``, ``org.hibernate``, ``org.jooq``, ``org.mvel2``, ``org.xml.sax``, ``org.xmlpull.v1``, ``play.mvc``, ``ratpack.core.form``, ``ratpack.core.handling``, ``ratpack.core.http``, ``ratpack.exec``, ``ratpack.form``, ``ratpack.func``, ``ratpack.handling``, ``ratpack.http``, ``ratpack.util``",39,99,151,,,,14,18,,
+    Others,"``cn.hutool.core.codec``, ``com.esotericsoftware.kryo.io``, ``com.esotericsoftware.kryo5.io``, ``com.fasterxml.jackson.core``, ``com.fasterxml.jackson.databind``, ``com.opensymphony.xwork2.ognl``, ``com.unboundid.ldap.sdk``, ``flexjson``, ``groovy.lang``, ``groovy.util``, ``jodd.json``, ``net.sf.saxon.s9api``, ``ognl``, ``org.apache.commons.codec``, ``org.apache.commons.jexl2``, ``org.apache.commons.jexl3``, ``org.apache.commons.ognl``, ``org.apache.directory.ldap.client.api``, ``org.apache.ibatis.jdbc``, ``org.apache.shiro.codec``, ``org.apache.shiro.jndi``, ``org.codehaus.groovy.control``, ``org.dom4j``, ``org.hibernate``, ``org.jooq``, ``org.mvel2``, ``org.xml.sax``, ``org.xmlpull.v1``, ``play.mvc``, ``ratpack.core.form``, ``ratpack.core.handling``, ``ratpack.core.http``, ``ratpack.exec``, ``ratpack.form``, ``ratpack.func``, ``ratpack.handling``, ``ratpack.http``, ``ratpack.util``",39,239,151,,,,14,18,,
-    Totals,,175,5332,408,13,6,10,107,33,1,66
+    Totals,,175,5472,408,13,6,10,107,33,1,66
  • Changes to framework-coverage-java.csv:
- ratpack.exec,,,26,,,,,,,,,,,,,,,,,,,,,,26
+ ratpack.exec,,,58,,,,,,,,,,,,,,,,,,,,,,58
- ratpack.func,,,5,,,,,,,,,,,,,,,,,,,,,,5
+ ratpack.func,,,59,,,,,,,,,,,,,,,,,,,,,,59
- ratpack.util,,,5,,,,,,,,,,,,,,,,,,,,,,5
+ ratpack.util,,,59,,,,,,,,,,,,,,,,,,,,,,59

@smowton
Copy link
Contributor

smowton commented Nov 17, 2021

Noting I haven't forgotten this bug and intend to look at it Friday or Monday

@smowton
Copy link
Contributor

smowton commented Nov 17, 2021

(Edit: apologies I had missed discussion between @atorralba and @aschackmull on this)

@JLLeitschuh
Copy link
Contributor Author

I think the bulk of the code changes here are "done" but I'm waiting on a fix for the bug in order to request this to be merged.

Could someone add the hacktoberfest-accepted label to this PR for me?

@aschackmull
Copy link
Contributor

Bug should be fixed now (#7187), so you should be able to get things working using just Field[..].

@JLLeitschuh JLLeitschuh force-pushed the feat/JLL/improve_ratpack_support branch from c4f2d27 to c079914 Compare November 22, 2021 18:45
@JLLeitschuh
Copy link
Contributor Author

First-time contributors need a maintainer to approve running workflows

😆

Bug should be fixed now (#7187), so you should be able to get things working using just Field[..].

Indeed! This does now work! The PR is updated! 😄

@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged.

Click to show differences in coverage

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    Others,"``cn.hutool.core.codec``, ``com.esotericsoftware.kryo.io``, ``com.esotericsoftware.kryo5.io``, ``com.fasterxml.jackson.core``, ``com.fasterxml.jackson.databind``, ``com.opensymphony.xwork2.ognl``, ``com.unboundid.ldap.sdk``, ``flexjson``, ``groovy.lang``, ``groovy.util``, ``jodd.json``, ``net.sf.saxon.s9api``, ``ognl``, ``org.apache.commons.codec``, ``org.apache.commons.jexl2``, ``org.apache.commons.jexl3``, ``org.apache.commons.ognl``, ``org.apache.directory.ldap.client.api``, ``org.apache.ibatis.jdbc``, ``org.apache.shiro.codec``, ``org.apache.shiro.jndi``, ``org.codehaus.groovy.control``, ``org.dom4j``, ``org.hibernate``, ``org.jooq``, ``org.mvel2``, ``org.xml.sax``, ``org.xmlpull.v1``, ``play.mvc``, ``ratpack.core.form``, ``ratpack.core.handling``, ``ratpack.core.http``, ``ratpack.exec``, ``ratpack.form``, ``ratpack.func``, ``ratpack.handling``, ``ratpack.http``, ``ratpack.util``",39,99,151,,,,14,18,,
+    Others,"``cn.hutool.core.codec``, ``com.esotericsoftware.kryo.io``, ``com.esotericsoftware.kryo5.io``, ``com.fasterxml.jackson.core``, ``com.fasterxml.jackson.databind``, ``com.opensymphony.xwork2.ognl``, ``com.unboundid.ldap.sdk``, ``flexjson``, ``groovy.lang``, ``groovy.util``, ``jodd.json``, ``net.sf.saxon.s9api``, ``ognl``, ``org.apache.commons.codec``, ``org.apache.commons.jexl2``, ``org.apache.commons.jexl3``, ``org.apache.commons.ognl``, ``org.apache.directory.ldap.client.api``, ``org.apache.ibatis.jdbc``, ``org.apache.shiro.codec``, ``org.apache.shiro.jndi``, ``org.codehaus.groovy.control``, ``org.dom4j``, ``org.hibernate``, ``org.jooq``, ``org.mvel2``, ``org.xml.sax``, ``org.xmlpull.v1``, ``play.mvc``, ``ratpack.core.form``, ``ratpack.core.handling``, ``ratpack.core.http``, ``ratpack.exec``, ``ratpack.form``, ``ratpack.func``, ``ratpack.handling``, ``ratpack.http``, ``ratpack.util``",39,177,151,,,,14,18,,
-    Totals,,175,5369,431,13,6,10,107,33,1,66
+    Totals,,175,5447,431,13,6,10,107,33,1,66
  • Changes to framework-coverage-java.csv:
- ratpack.exec,,,26,,,,,,,,,,,,,,,,,,,,,,,26
+ ratpack.exec,,,48,,,,,,,,,,,,,,,,,,,,,,,48
- ratpack.func,,,5,,,,,,,,,,,,,,,,,,,,,,,5
+ ratpack.func,,,33,,,,,,,,,,,,,,,,,,,,,,,33
- ratpack.util,,,5,,,,,,,,,,,,,,,,,,,,,,,5
+ ratpack.util,,,33,,,,,,,,,,,,,,,,,,,,,,,33

@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged.

Click to show differences in coverage

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    Others,"``cn.hutool.core.codec``, ``com.esotericsoftware.kryo.io``, ``com.esotericsoftware.kryo5.io``, ``com.fasterxml.jackson.core``, ``com.fasterxml.jackson.databind``, ``com.opensymphony.xwork2.ognl``, ``com.unboundid.ldap.sdk``, ``flexjson``, ``groovy.lang``, ``groovy.util``, ``jodd.json``, ``net.sf.saxon.s9api``, ``ognl``, ``org.apache.commons.codec``, ``org.apache.commons.jexl2``, ``org.apache.commons.jexl3``, ``org.apache.commons.ognl``, ``org.apache.directory.ldap.client.api``, ``org.apache.ibatis.jdbc``, ``org.apache.shiro.codec``, ``org.apache.shiro.jndi``, ``org.codehaus.groovy.control``, ``org.dom4j``, ``org.hibernate``, ``org.jooq``, ``org.mvel2``, ``org.xml.sax``, ``org.xmlpull.v1``, ``play.mvc``, ``ratpack.core.form``, ``ratpack.core.handling``, ``ratpack.core.http``, ``ratpack.exec``, ``ratpack.form``, ``ratpack.func``, ``ratpack.handling``, ``ratpack.http``, ``ratpack.util``",39,99,151,,,,14,18,,
+    Others,"``cn.hutool.core.codec``, ``com.esotericsoftware.kryo.io``, ``com.esotericsoftware.kryo5.io``, ``com.fasterxml.jackson.core``, ``com.fasterxml.jackson.databind``, ``com.opensymphony.xwork2.ognl``, ``com.unboundid.ldap.sdk``, ``flexjson``, ``groovy.lang``, ``groovy.util``, ``jodd.json``, ``net.sf.saxon.s9api``, ``ognl``, ``org.apache.commons.codec``, ``org.apache.commons.jexl2``, ``org.apache.commons.jexl3``, ``org.apache.commons.ognl``, ``org.apache.directory.ldap.client.api``, ``org.apache.ibatis.jdbc``, ``org.apache.shiro.codec``, ``org.apache.shiro.jndi``, ``org.codehaus.groovy.control``, ``org.dom4j``, ``org.hibernate``, ``org.jooq``, ``org.mvel2``, ``org.xml.sax``, ``org.xmlpull.v1``, ``play.mvc``, ``ratpack.core.form``, ``ratpack.core.handling``, ``ratpack.core.http``, ``ratpack.exec``, ``ratpack.form``, ``ratpack.func``, ``ratpack.handling``, ``ratpack.http``, ``ratpack.util``",39,177,151,,,,14,18,,
-    Totals,,175,5369,431,13,6,10,107,33,1,66
+    Totals,,175,5447,431,13,6,10,107,33,1,66
  • Changes to framework-coverage-java.csv:
- ratpack.exec,,,26,,,,,,,,,,,,,,,,,,,,,,,26
+ ratpack.exec,,,48,,,,,,,,,,,,,,,,,,,,,,,48
- ratpack.func,,,5,,,,,,,,,,,,,,,,,,,,,,,5
+ ratpack.func,,,33,,,,,,,,,,,,,,,,,,,,,,,33
- ratpack.util,,,5,,,,,,,,,,,,,,,,,,,,,,,5
+ ratpack.util,,,33,,,,,,,,,,,,,,,,,,,,,,,33

Comment on lines +106 to +107
"pushLeft;(Object);;Argument[-1];" + right + " of ReturnValue;value",
"pushRight;(Object);;Argument[-1];" + left + " of ReturnValue;value",
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing: arg0 -> left/right of returnval

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 were indeed correct. Thank you for spotting this! I'm impressed with how thoroughly you check these PR's. I would have missed this as a reviewer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should now be fixed. See below.

"next;;;Argument[-1];ReturnValue;value",
"nextOp;;;Element of Argument[-1];Parameter[0] of Argument[0];value",
"flatOp;;;Element of Argument[-1];Parameter[0] of Argument[0];value",
// `nextOpIf` accesses qualfier the 'Promise' value and also returns the qualifier
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// `nextOpIf` accesses qualfier the 'Promise' value and also returns the qualifier
// `nextOpIf` accesses qualifier the 'Promise' value and also returns the qualifier

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I blame GitHub copilot 😆

// `blockingOp` passes the value to the argumet
"blockingOp;;;Element of Argument[-1];Parameter[0] of Argument[0];value",
// `replace` returns the passed `Promise`
"replace;;;Argument[0];ReturnValue;value",
Copy link
Contributor

Choose a reason for hiding this comment

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

The doc and the source both read like you get a new promise back, that discards the outcome of this and replaces it with the outcome of arg0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not quite, it's not discarding the promise, because everything earlier in the chain still needs to execute.

Here's how the method is implemented on the interface:

  /**
   * Replaces {@code this} promise with the provided promise for downstream subscribers.
   * <p>
   * This is simply a more convenient form of {@link #flatMap(Function)}, where the given promise is returned.
   * This method can be used when a subsequent operation on a promise isn't dependent on the actual promised value.
   * <p>
   * If the upstream promise fails, its error will propagate downstream and the given promise will never be subscribed to.
   *
   * <pre class="java">{@code
   * import ratpack.test.exec.ExecHarness;
   * import ratpack.exec.ExecResult;
   * import ratpack.exec.Promise;
   *
   * import static org.junit.Assert.assertEquals;
   *
   * public class Example {
   *   private static String value;
   *
   *   public static void main(String... args) throws Exception {
   *     ExecResult<String> result = ExecHarness.yieldSingle(c ->
   *         Promise.value("foo")
   *           .next(v -> value = v)
   *           .replace(Promise.value("bar"))
   *     );
   *
   *     assertEquals("bar", result.getValue());
   *     assertEquals("foo", value);
   *   }
   * }
   * }</pre>
   *
   * @param next the promise to replace {@code this} with
   * @param <O> the type of the value of the replacement promise
   * @return a promise
   * @since 1.1
   */
  default <O> Promise<O> replace(Promise<O> next) {
    return flatMap(in -> next);
  }

https://github.com/ratpack/ratpack/blob/1a5d97a011930335fdc97b20a638b6afb070a4a4/ratpack-exec/src/main/java/ratpack/exec/Promise.java#L767-L805

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, but that's a fresh object, so we don't have value-flow from next to the return value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean, sure, but the semantics are the same from a CodeQL perspective, are they not?

Copy link
Contributor

Choose a reason for hiding this comment

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

Generally we would call aliases value-flow and anything else taint-flow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I've updated this to be replace;;;Element of Argument[0];Element of ReturnValue;value

JLLeitschuh and others added 2 commits November 25, 2021 12:55
Adds models for `ratpack.func.Pair`, and `ratpack.exec.Result`.
Improve moels for `ratpack.exec.Promise`.

Signed-off-by: Jonathan Leitschuh <Jonathan.Leitschuh@gmail.com>
@JLLeitschuh JLLeitschuh force-pushed the feat/JLL/improve_ratpack_support branch from 5cc1d98 to 36bb84d Compare November 25, 2021 17:56
@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged.

Click to show differences in coverage

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    Others,"``cn.hutool.core.codec``, ``com.esotericsoftware.kryo.io``, ``com.esotericsoftware.kryo5.io``, ``com.fasterxml.jackson.core``, ``com.fasterxml.jackson.databind``, ``com.opensymphony.xwork2.ognl``, ``com.unboundid.ldap.sdk``, ``flexjson``, ``groovy.lang``, ``groovy.util``, ``jodd.json``, ``net.sf.saxon.s9api``, ``ognl``, ``org.apache.commons.codec``, ``org.apache.commons.jexl2``, ``org.apache.commons.jexl3``, ``org.apache.commons.ognl``, ``org.apache.directory.ldap.client.api``, ``org.apache.ibatis.jdbc``, ``org.apache.shiro.codec``, ``org.apache.shiro.jndi``, ``org.codehaus.groovy.control``, ``org.dom4j``, ``org.hibernate``, ``org.jooq``, ``org.mvel2``, ``org.xml.sax``, ``org.xmlpull.v1``, ``play.mvc``, ``ratpack.core.form``, ``ratpack.core.handling``, ``ratpack.core.http``, ``ratpack.exec``, ``ratpack.form``, ``ratpack.func``, ``ratpack.handling``, ``ratpack.http``, ``ratpack.util``",39,99,151,,,,14,18,,
+    Others,"``cn.hutool.core.codec``, ``com.esotericsoftware.kryo.io``, ``com.esotericsoftware.kryo5.io``, ``com.fasterxml.jackson.core``, ``com.fasterxml.jackson.databind``, ``com.opensymphony.xwork2.ognl``, ``com.unboundid.ldap.sdk``, ``flexjson``, ``groovy.lang``, ``groovy.util``, ``jodd.json``, ``net.sf.saxon.s9api``, ``ognl``, ``org.apache.commons.codec``, ``org.apache.commons.jexl2``, ``org.apache.commons.jexl3``, ``org.apache.commons.ognl``, ``org.apache.directory.ldap.client.api``, ``org.apache.ibatis.jdbc``, ``org.apache.shiro.codec``, ``org.apache.shiro.jndi``, ``org.codehaus.groovy.control``, ``org.dom4j``, ``org.hibernate``, ``org.jooq``, ``org.mvel2``, ``org.xml.sax``, ``org.xmlpull.v1``, ``play.mvc``, ``ratpack.core.form``, ``ratpack.core.handling``, ``ratpack.core.http``, ``ratpack.exec``, ``ratpack.form``, ``ratpack.func``, ``ratpack.handling``, ``ratpack.http``, ``ratpack.util``",39,181,151,,,,14,18,,
-    Totals,,175,5369,431,13,6,10,107,33,1,66
+    Totals,,175,5451,431,13,6,10,107,33,1,66
  • Changes to framework-coverage-java.csv:
- ratpack.exec,,,26,,,,,,,,,,,,,,,,,,,,,,,26
+ ratpack.exec,,,48,,,,,,,,,,,,,,,,,,,,,,,48
- ratpack.func,,,5,,,,,,,,,,,,,,,,,,,,,,,5
+ ratpack.func,,,35,,,,,,,,,,,,,,,,,,,,,,,35
- ratpack.util,,,5,,,,,,,,,,,,,,,,,,,,,,,5
+ ratpack.util,,,35,,,,,,,,,,,,,,,,,,,,,,,35

@JLLeitschuh
Copy link
Contributor Author

Java QLDoc Checks (GitHub Actions)

I see that this is failing, but I can't see the failures because that repository is not public.

@atorralba
Copy link
Contributor

Java QLDoc Checks (GitHub Actions)

I see that this is failing, but I can't see the failures because that repository is not public.

I re-launched it because it seemed a transient error. Now it's all green.

@smowton smowton merged commit 27f40e0 into github:main Nov 29, 2021
@JLLeitschuh JLLeitschuh deleted the feat/JLL/improve_ratpack_support branch November 29, 2021 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants