codeconsole commented on code in PR #16142:
URL: https://github.com/apache/grails-core/pull/16142#discussion_r3779509126
##########
grails-gsp/core/src/main/groovy/org/grails/gsp/compiler/GroovyPageParser.java:
##########
@@ -1380,6 +1391,54 @@ public void setLastModified(long lastModified) {
this.lastModified = lastModified;
}
+ /**
+ * Computes the checksum recorded in the {@code SOURCE_CHECKSUM} constant
of a generated page.
+ * <p>
+ * Both the compiler that writes the constant and the runtime that
compares against it use this method, so
+ * that the two can never disagree on how a GSP source is digested. The
stream is read to the end but is
+ * not closed; closing it remains the caller's responsibility.
+ *
+ * @param source the raw bytes of the GSP source
+ * @return the checksum as a lower-case hex string
+ * @throws IOException if the source cannot be read
+ * @since 7.0.16
+ */
+ public static String checksumOf(InputStream source) throws IOException {
Review Comment:
Correction to my reply above — you were right and my reasoning wasn't. Fixed
in `7920a56816`.
I said one wrapper had to stay because `GroovyPageParser`'s constructor
takes an `InputStream`. That's true of the signature but not of the class: the
`InputStream` constructor is a thin delegate that calls `readStream` — which is
just `IOUtils.toString(in, encoding)` with a default — and forwards to the
`String` constructor with identical `expressionCodecName` and `ConfigMap`
semantics.
So the compiler can call that constructor directly. Both wrappers are now
gone, along with the `withStream` closure that had wrapped the whole compile
body, and it still reads the file once. It also removes a hop through an
overload that existed only to decode.
I checked the constructor's signature and not its body, which is how I
talked myself into a constraint that wasn't there.
`GroovyPageCompilerReproducibilitySpec` and `ParseSpec` re-run clean.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]