RFR: 8300176: URLEncoder/URLDecoder static fields should be private static final

David Schlosnagle duke at openjdk.org
Tue Jan 24 00:56:11 UTC 2023


On Fri, 20 Jan 2023 17:41:55 GMT, Darragh Clarke <duke at openjdk.org> wrote:

> Made the `static` fields `private static final`, updated the naming as well to reflect this.
> 
> This meant I updated `URLDecoder` to set the `DEFAULT_ENCODING_NAME` itself since it had been previously getting it from `URLEncoder`.
> 
> Since these fields are only referenced from inside the classes nothing else needed updated

Curious if we could remove a couple of the static fields

src/java.base/share/classes/java/net/URLDecoder.java line 99:

> 97:         DEFAULT_ENCODING_NAME = StaticProperty.fileEncoding();
> 98:     }
> 99: 

Can we just in-line the use of `StaticProperty.fileEncoding()` to the call site as `StaicProperty.FILE_ENCODING` is already stored in a static final field

Suggestion:



https://github.com/openjdk/jdk/blob/77a50105f0c4a4cb7286dda13c633f1e69295210/src/java.base/share/classes/jdk/internal/util/StaticProperty.java#L54-L74

src/java.base/share/classes/java/net/URLDecoder.java line 117:

> 115: 
> 116:         try {
> 117:             str = decode(s, DEFAULT_ENCODING_NAME);

Suggestion:

            str = decode(s, StaticProperty.fileEncoding());

src/java.base/share/classes/java/net/URLEncoder.java line 82:

> 80:     private static final BitSet DONT_NEED_ENCODING;
> 81:     private static final int CASE_DIFF = ('a' - 'A');
> 82:     private static final String DEFAULT_ENCODING_NAME;

Similar to above, can we inline usages?

Suggestion:

src/java.base/share/classes/java/net/URLEncoder.java line 140:

> 138:         DONT_NEED_ENCODING.set('*');
> 139: 
> 140:         DEFAULT_ENCODING_NAME = StaticProperty.fileEncoding();

Suggestion:

src/java.base/share/classes/java/net/URLEncoder.java line 165:

> 163: 
> 164:         try {
> 165:             str = encode(s, DEFAULT_ENCODING_NAME);

Suggestion:

            str = encode(s, StaticProperty.fileEncoding());

-------------

PR: https://git.openjdk.org/jdk/pull/12122


More information about the net-dev mailing list