-
Notifications
You must be signed in to change notification settings - Fork 8
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
Invoke evilurl via Bazel #1202
base: main
Are you sure you want to change the base?
Invoke evilurl via Bazel #1202
Conversation
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.
Hello @vorburger, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request introduces a new Bazel test, evilurl
, which checks for forbidden usages of java.net.URL
in Java files. It also includes changes to the URL
class (formerly IRI
), Singleton
, MediaTypes
, ClasspathResource
, FileResourceTest
, MediaTypeDetector
, ResourceProvider
, ResourceProvidersTest
, and UrlResource
to improve URL handling and resource loading. The author is encountering an error when building the evilurl
test and is seeking assistance in resolving it.
Highlights
- New Bazel Test: Adds a
sh_test
namedevilurl
to check for forbiddenjava.net.URL
usages. - URL Class Updates: Renames
IRI
class toURL
and updates related references, aiming to replace usages of the problematicjava.net.URL
. - Resource Loading Improvements: Modifies
ClasspathResource
,FileResourceTest
,MediaTypeDetector
,ResourceProvider
, andUrlResource
to enhance resource loading and media type detection. - Singleton Class Enhancement: Adds an
isSet()
method to theSingleton
class for checking if a value is set.
Changelog
Click here to see the changelog
- BUILD
- Added a
sh_test
rule forevilurl
that includes all Java files as data.
- Added a
- java/dev/enola/common/context/Singleton.java
- Added an
isSet()
method to check if the singleton value is set (lines 71-73).
- Added an
- java/dev/enola/common/io/iri/URIs.java
- Removed import of
java.net.URL
(line 34). - Removed
create(URL url)
method (lines 340-346).
- Removed import of
- java/dev/enola/common/io/iri/URL.java
- Renamed class from
IRI
toURL
(line 107). - Updated documentation to reflect the change from IRI to URL.
- Updated method names and references to use
URL
instead ofIRI
(e.g.,equalsNormalized(URL o)
on line 334,compareTo(URL o)
on line 359). - Updated
parseUnencoded
to returnURL
instead ofIRI
(lines 144-147). - Updated
from
to returnURL
instead ofIRI
(lines 153-156). - Updated builder methods to return
URL
instead ofIRI
(lines 186-195). - Updated resolve and relativize methods to use URL instead of IRI (lines 295-307).
- Updated normalize method to return URL instead of IRI (lines 324-327).
- Updated ValidationException to use URL instead of IRI (lines 411-433).
- Renamed class from
- java/dev/enola/common/io/iri/URLTest.java
- Renamed class from
IRITest
toURLTest
(line 30). - Renamed
TestIRI
record toTestURL
(line 32). - Updated tests to use
TestURL
instead ofTestIRI
(line 44). - Updated tests to use
URL
instead ofIRI
(lines 72, 75, 85, 88, 92, 106). - Updated assertThrows to use URL.ValidationException instead of IRI.ValidationException (line 102).
- Renamed class from
- java/dev/enola/common/io/mediatype/MediaTypes.java
- Added a check for
MediaTypeProviders.SINGLETON.isSet()
before callingget()
(lines 52-54).
- Added a check for
- java/dev/enola/common/io/resource/ClasspathResource.java
- Added a TODO comment to replace with ClassLoaderResource (line 32).
- java/dev/enola/common/io/resource/FileResourceTest.java
- Added import for
java.net.URISyntaxException
(line 44). - Added URISyntaxException to jarScheme method signature (line 94).
- Modified jarScheme method to use URI instead of URL (lines 95-96).
- Added import for
- java/dev/enola/common/io/resource/MediaTypeDetector.java
- Added a check for
MediaTypeProviders.SINGLETON.isSet()
before callingget()
(lines 152-154).
- Added a check for
- java/dev/enola/common/io/resource/ResourceProvider.java
- Removed URL related methods (lines 72-94).
- java/dev/enola/common/io/resource/ResourceProvidersTest.java
- Removed import for
com.google.common.io.Resources
(line 27). - Removed testJarScheme method (lines 170-174).
- Removed import for
- java/dev/enola/common/io/resource/UrlResource.java
- Added a TODO comment to remove once there is a ClassLoaderResource (line 47).
- Removed import for
dev.enola.common.io.iri.URIs
(line 25). - Replaced URIs.create(url) with create(url) method (lines 105, 109).
- Added create(URL url) method (lines 113-119).
- java/dev/enola/common/io/resource/UrlResourceTest.java
- Added imports for
com.google.common.io.Resources
(line 22),java.io.IOException
(line 26), andjava.net.URISyntaxException
(line 27). - Added testJarScheme method (lines 39-43).
- Added imports for
- tools/evilurl/BUILD
- Added a
sh_binary
rule forevilurl
(lines 1-5).
- Added a
- tools/evilurl/test.bash
- Created a bash script to detect usages of
java.net.URL
in Java files (lines 1-57).
- Created a bash script to detect usages of
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Did you know?
The first URL was created in 1991 by Tim Berners-Lee, the inventor of the World Wide Web. It pointed to the first website, which was a description of the World Wide Web project itself.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces a new Bazel target for evilurl
, a script designed to detect usages of java.net.URL
in Java files. It also includes changes to the URL
class, renaming it from IRI
and adding functionality. The Singleton
class is also updated with an isSet()
method. Overall, the changes seem well-structured, but there are a few points that need attention.
Summary of Findings
- Incorrect
srcs
attribute insh_test
: Thesrcs
attribute in thesh_test
rule in theBUILD
file should point to the actual script file, not the directory. This is causing the Bazel build to fail. - Inconsistent naming and TODOs in
URL.java
: The class was renamed fromIRI
toURL
, but there are still references toIRI
in the code and TODOs. These should be updated for consistency. - Missing
URISyntaxException
import inFileResourceTest.java
: TheFileResourceTest.java
file is missing an import forjava.net.URISyntaxException
, which is now required due to the changes in thejarScheme()
method.
Merge Readiness
The pull request is not ready for merging due to the critical issue with the Bazel build configuration. The high severity issues related to naming inconsistencies and missing imports should also be addressed before merging. I am unable to approve this pull request, and recommend that it not be merged until these issues are resolved. Please have others review and approve this code before merging.
BUILD
Outdated
|
||
sh_test( | ||
name = "evilurl", | ||
srcs = ["//tools/evilurl"], |
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.
@@ -103,7 +104,8 @@ | |||
* @author <a href="https://www.vorburger.ch">Michael Vorburger.ch</a> originally wrote this class | |||
* for <a href="https://enola.dev">Enola.dev</a>. | |||
*/ | |||
public final class IRI implements Comparable<IRI> { | |||
public final class URL implements Comparable<URL> { | |||
// TODO extends IRI |
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.
/** Equality check, with {@link #normalize()}-ation. */ | ||
public boolean equalsNormalized(IRI o) { | ||
public boolean equalsNormalized(URL o) { |
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.
450ff09
to
1c7012a
Compare
NOK Draft, WIP;
bazelisk test //java:evilurl
still fails (now) with:because there are (of course) [many other]
BUILD
file withinjava/
... which makes Bazel "hide" their**/*.java
.How does one do this, with Bazel? There must be some way.
Asked on https://stackoverflow.com/q/79495663/421602.
Might this be a way? Complicated...