This file lists the changes in each release that affect code using the library. The format follows Keep a Changelog. Releases before 3.0.0 are listed in the Git tags.
Version 3 encodes URLs by the rules of RFC 3986, adds a way to sign URLs, signs S3 URLs with Signature Version 4, and fixes several bugs in the S3 and CloudFront builders. Some URLs differ from the ones version 2 produced, so read the upgrade notes first.
-
Pass the bucket's region to every signed S3 URL.
S3UrlBuildernow signs with AWS Signature Version 4 (SigV4) by default, because AWS is retiring Signature Version 2 (SigV2) for S3. A signed URL needs the bucket's region, frominRegion(region)or the newwithEndpoint(endpoint, region); without one,toString()throwsIllegalStateException.withEndpoint(endpoint)clears any region thatinRegionset. The region must be the bucket's own: code that passes the application's region toinRegionsigns for the wrong region when the bucket lives in another one, and S3 answers the request with a 400. A SigV4 URL lasts from 1 second to 7 days, andtoString()throwsIllegalArgumentExceptionfor an expiration outside that range. The URL carriesX-Amz-Algorithm,X-Amz-Credential,X-Amz-Date,X-Amz-Expires,X-Amz-SignedHeaders,X-Amz-Signature, and with a session tokenX-Amz-Security-Token, in place ofSignature,Expires,AWSAccessKeyId, andx-amz-security-token. To keep SigV2 for a bucket or S3-compatible service that still accepts it, call the deprecatedusingSignatureVersion2(). -
Check the URLs you generate. The default encoding changed. A path segment now keeps
@,:, and!$&'()*+,;=, and a query parameter now encodes*and keeps~.new UrlBuilder("my.host.com", "a b+c@d").addParameter("q", "x y*z~").toString() // 2.x: http://my.host.com/a%20b%2Bc%40d?q=x%20y*z%7E // 3.0: http://my.host.com/a%20b+c@d?q=x%20y%2Az~
Both forms decode to the same text. To get the 2.x output back, call
usingLegacyEncoding()on the builder.new UrlBuilder("my.host.com", "a b+c@d") .usingLegacyEncoding() .addParameter("q", "x y*z~") .toString() // http://my.host.com/a%20b%2Bc%40d?q=x%20y*z%7E
To switch back only the path or only the query string, pass a
LegacyEncodertousingPathEncoderorusingQueryEncoder.builder.usingPathEncoder(new LegacyEncoder()); // 2.x path, 3.0 query string builder.usingQueryEncoder(new LegacyEncoder()); // 3.0 path, 2.x query string
The switch applies to the whole URL whenever you call it, including a URL that
new UrlBuilder(String)parsed.new UrlBuilder("http://my.host.com/a%20b%2Bc%40d?q=x%20y*z%7E").usingLegacyEncoding().toString() // http://my.host.com/a%20b%2Bc%40d?q=x%20y*z%7E
It has two limits:
- A parameter added with its own encoder, through
addParameter(key, value, encoder), keeps that encoder. S3UrlBuilderandCloudfrontUrlBuilderalways use the 3.0 encoding. Their keys encode every character except letters, digits,-._~, and/, as the AWS SDKs do, so they differ from 2.x only in writing*as%2Aand keeping~.
- A parameter added with its own encoder, through
-
Replace
usingEncoder(Encoder). CallusingPathEncoder(Encoder),usingQueryEncoder(Encoder), or both.LegacyEncoderreplacesBuiltinEncoder. Check code that calls it after adding parameters:usingEncoderencoded only the parameters added after the call, andusingQueryEncoderencodes every parameter, including the ones added before it. To encode one parameter differently, pass its encoder toaddParameter(key, value, encoder). -
Expect unencoded text from
getPath(),getPathSegments(), andS3UrlBuilder.getKey(). They returned percent-encoded text in 2.x.getKey()now returns the key as given, without leading slashes. -
Check code that parses a URL and writes it back.
new UrlBuilder(String)now decodes the path, so/a%20bstays/a%20b. In 2.x it became/a%2520b. A trailing slash now stays as well, so/foo/no longer becomes/foo. Check S3 and CloudFront keys that end with a slash or contain//too: both builders now keep those slashes, and write each slash after the first of a run as%2F, soa//bbecomes/a/%2Fb. A+in the query string still reads as a space, as in 2.x, and is written back as%20. A percent-encoded sequence that is not UTF-8, such as/caf%E9, now throwsIllegalArgumentException, because the builder cannot write that URL back unchanged. -
Check code that adds a parameter whose value is only whitespace.
addParameter("q", " ")now writesq=%20. In 2.x it wroteqalone, as a null or empty value still does. -
Check code that calls both
expireInandexpireAt. The later call now wins. In 2.xexpireAtalways won. -
Check code that passes zero, a negative number, or null as an expiration.
expireInnow throwsIllegalArgumentExceptionfor a zero or negative duration, andexpireAtthrows it for null. In 2.xS3UrlBuilder.expireIn(0, unit)produced an unsigned URL, andexpireAt(null)cleared the expiration. -
Check
S3UrlBuildercalls that version 2 accepted.withContentTypenow requires a signed URL, aswithAttachmentFilenamedoes, because S3 rejects an anonymous request that setsresponse-content-type. Without an expiration and credentials,toString()throwsIllegalStateException.withKeyand the constructor throwIllegalArgumentExceptionfor a key of only slashes, which named the bucket itself.inRegionthrows it for a blank region, andwithEndpointthrows it for a blank endpoint. -
Move from
expireAt(Date)toexpireAt(Instant). TheDateoverload still works and is deprecated. -
Check code that pairs a scheme with port 80 or 443, or reads
getPort(). The port now wins over the scheme:https://host:80/parses ashttp://host/, andsetPort(80)turns HTTPS off. AusingSsl(boolean)call after the port keeps the port, sonew UrlBuilder("host", 80, "a").usingSsl()writeshttps://host:80/awhere 2.x wrotehttps://host/a.new UrlBuilder(hostname, path)sets no port, so itsgetPort()returns 0 where 2.x returned 80. A URL parsed without a port returns 0 as well, where 2.x returned -1. -
Update any rule that names the BouncyCastle artifacts. The library now depends on
bcprov-jdk18onandbcpkix-jdk18on1.87, where 2.x depended onbcprov-jdk15to18andbcpkix-jdk15to181.80. -
Expect
httpsfromS3UrlBuilderandCloudfrontUrlBuilder. Both now write an HTTPS URL by default, where 2.x wrotehttp, so a signature and a session token no longer travel in clear text. To keephttp, callusingSsl(false)onS3UrlBuilderor the newwithSsl(false)onCloudfrontUrlBuilder. A CloudFront signature covers the scheme, so CloudFront rejects a link signed forhttpsthat is requested overhttp. -
Check S3 URLs for a bucket whose name contains a period. In an HTTPS URL the bucket now goes in the path, as in
https://s3.amazonaws.com/my.bucket/key.txt, because the endpoint's wildcard certificate does not matchmy.bucket.s3.amazonaws.com. A path-style URL reaches a bucket outsideus-east-1only through its regional endpoint, so callinRegionfor such a bucket. A bucket also goes in the path when the endpoint is an IP address. AnhttpURL andusingBucketVirtualHost()keep the bucket in the hostname. -
Check
CloudfrontUrlBuildercalls that version 2 accepted. The constructor andwithKeythrowIllegalArgumentExceptionfor a key that is blank or only slashes, which signed the root of the distribution.addParameterthrows it forExpires,Signature,Key-Pair-Id, andPolicy, which CloudFront reads the signature from. -
Give a protocol-relative URL a hostname.
toString()now throwsIllegalArgumentExceptionfor a blank hostname in protocol-relative mode, as it does in fully qualified mode. In 2.x it wrote//null/path. -
Stop importing
StringUtilsInternalandInternalUtils. The two helper classes are no longer public.
UrlSignerandUrlBuilder.usingUrlSigner(UrlSigner)add a signature of your own to any URL. The signer receives aSigningContext, adds any parameter the signature must cover withaddParameter, signsgetStringToSign(), and returns the query parameters to append.PathSegmentEncoderandQueryParameterEncoderencode by RFC 3986, andusingPathEncoder(Encoder)andusingQueryEncoder(Encoder)set them separately.LegacyEncoderandusingLegacyEncoding()produce the encoding of 2.x.NoEncodingEncoder.INSTANCEis a shared instance of that encoder.S3UrlBuilderandCloudfrontUrlBuildergainexpireAt(Instant)andexpireIn(Duration).S3UrlBuilder.withEndpoint(endpoint, region)sets a custom endpoint and the region Signature Version 4 signs for.CloudfrontUrlBuilder.withSsl(boolean)sets the scheme, asS3UrlBuilder.usingSsl(boolean)does.CloudfrontPrivateKeyUtils.fromPemStringreads PKCS#8 keys (BEGIN PRIVATE KEY) as well as PKCS#1 keys.- The jar declares the module name
com.widen.urlbuilderthroughAutomatic-Module-Name.
S3UrlBuildersigns with AWS Signature Version 4 by default. A signed URL needs the bucket's region and lasts at most 7 days.inRegionsets the signing region, andwithEndpoint(endpoint)clears it.- Path segments and query parameters are encoded by RFC 3986, with separate rules for each.
- The builder encodes the path when it writes the URL, so
getPath()andgetPathSegments()return unencoded text, andS3UrlBuilder.getKey()returns the key as given. new UrlBuilder(String)decodes the path of the URL it parses.- A parameter value of only whitespace is written, as in
q=%20. A null or empty value still writes the name alone. - Port 80 turns HTTPS off, as port 443 turns it on, and
new UrlBuilder(hostname, path)sets no port. expireInandexpireAtreplace each other, so the later call sets the expiration.expireInrejects a zero or negative duration, andexpireAtrejects null.S3UrlBuilder.withContentTyperequires a signed URL,withKeyrejects a key of only slashes,inRegionrejects a blank region, andwithEndpointrejects a blank endpoint.S3UrlBuilderwrites the host in lower case and leaves out the default port of the scheme, sowithEndpoint("MinIO.example.com:443", region).usingSsl()writeshttps://bucket.minio.example.com/. The SigV4 signature covers that host.CloudfrontUrlBuilderwrites and signs the distribution hostname the same way.S3UrlBuilderandCloudfrontUrlBuilderwrite an HTTPS URL by default.S3UrlBuilderputs the bucket in the path when its name contains a period and the URL is HTTPS, and when the endpoint is an IP address.S3UrlBuilder.inRegionreads the region in lower case, so the signature names the region as the host does.CloudfrontUrlBuilderrejects a key that is blank or only slashes, andaddParameterrejects the parameter names CloudFront reads the signature from.new UrlBuilder(String),PathSegmentEncoder.decode, andQueryParameterEncoder.decodethrowIllegalArgumentExceptionfor a percent-encoded sequence that is not UTF-8. They wrote U+FFFD in its place.UrlBuilder.toString()throwsIllegalArgumentExceptionfor a blank hostname in protocol-relative mode.UrlBuilder.getPort()returns 0 for a URL parsed without a port and for a negative port.- An expiration past
Instant.MAXthrowsIllegalArgumentExceptioninstead ofArithmeticException. toURL()wraps aMalformedURLExceptionin aRuntimeException.NoEncodingEncoderis final.- The BouncyCastle dependency is
bcprov-jdk18onandbcpkix-jdk18on1.87.
S3UrlBuilder.expireAt(Date)andCloudfrontUrlBuilder.expireAt(Date). UseexpireAt(Instant).LegacyEncoderandusingLegacyEncoding(). They exist to ease the move from 2.x.S3UrlBuilder.usingSignatureVersion2(), which signs with Signature Version 2 for buckets and S3-compatible services that still accept it. Sign with Signature Version 4 instead.
UrlBuilder.usingEncoder(Encoder). UseusingPathEncoder(Encoder)andusingQueryEncoder(Encoder).BuiltinEncoder. UseLegacyEncoderfor the same output.StringUtilsInternalandInternalUtilsfrom the public API. They are helpers for the library's own code.
S3UrlBuildersigned a URL that S3 rejected when the URL set both an attachment file name and a content type.S3UrlBuilder.toString()left parameters behind when it threw, and the next call wrote and signed them twice.S3UrlBuilder.usingCredentials(key, secret)kept the session token of an earlier call and signed it, so S3 rejected every URL after a switch from temporary to long-term credentials.- A
Content-Dispositionheader wrote*unencoded infilename*, so a strict parser ignored the UTF-8 file name. CloudfrontPrivateKeyUtils.fromPemStringbuilt a new BouncyCastle provider on every call.CloudfrontUrlBuildercould sign one expiration and write another when the clock passed a second boundary during signing, and CloudFront rejected that URL.CloudfrontUrlBuilderandS3UrlBuilderproduced wrong URLs and signatures when several threads calledtoString()on one builder.CloudfrontUrlBuilder.addParameterandUrlBuilder.addParametersthrewNullPointerExceptionfor a null value. A null value now adds the name alone.new UrlBuilder(String)mishandled a query value that contains=. It removed trailing=characters, so?sig=abc==parsed asabc, and it dropped the whole parameter for a value such as?a=b=c.new UrlBuilder(String)encoded an already encoded path a second time.new UrlBuilder(String)dropped the trailing slash of a path, so/foo/became/foo.S3UrlBuilderandCloudfrontUrlBuilderdropped a trailing slash and empty segments from a key, sofolder/anda//bnamed the objectsfolderanda/b.UrlBuilderleft port 80 out of anhttpsURL and port 443 out of anhttpURL, so the URL named the wrong port.SigningContext.getPort()returned null for those ports as well.S3UrlBuilder.inRegionwrote anamazonaws.comhost for a China region such ascn-north-1, whose endpoint ends inamazonaws.com.cn.
- On Java 9 and later, the file name in a
Content-Dispositionheader kept\,", and%. A file name containing"could add afilename*parameter and change the name a browser saves the download under.withAttachmentFilenamenow removes those characters on every Java version. S3UrlBuilderput any bucket name without uppercase letters,_,!,@, or#in the hostname, so a name containing/or?sent the URL, with its access key ID and signature, to another host. A bucket name with any character other than lowercase letters, digits,., and-now goes in the path.- A key of only slashes, such as
/, madeS3UrlBuildersign the bucket itself, a URL that lists the bucket's keys. - A null, empty, or slash-only key made
CloudfrontUrlBuildersign the root of the distribution. - A protocol-relative
UrlBuilderwith an empty hostname wrote///path, which a browser reads as a link to the host that the first path segment names. - The parser read
%followed by digits of another script, such as the fullwidth2E, as a percent-encoded byte, so%2E%2Ecame out as..after a filter had found no dots in the URL. It now reads only ASCII hex digits. - BouncyCastle 1.87 includes the fixes for CVE-2025-14813, CVE-2026-5588, CVE-2026-8763, and CVE-2026-13506.