Skip to content
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

InternetDomainName.topPrivateDomain() throws exception for Amazonaws-Domain #7151

Closed
1 task done
kindlerm1958 opened this issue Apr 11, 2024 · 4 comments
Closed
1 task done
Labels
type=defect Bug, not working as expected

Comments

@kindlerm1958
Copy link

Description

We just noticed that the method InternetDomainName.topPrivateDomain() throws an IllegalStateException for the host s3-eu-west-1.amazonaws.com. Strange: replacing the "s3" by something else works as expected.

Example

import com.google.common.net.InternetDomainName; 

public class GuavaTest {

	public static void main(String[] args) {
		final String host = "s3-eu-west-1.amazonaws.com"; //s4-eu-west-1.amazonaws.com works
		
		InternetDomainName domainName = InternetDomainName.from(host);
		if (domainName.hasPublicSuffix()) {
			System.out.println(host + " hasPublicSuffix");
            System.out.println("topPrivateDomain: " + domainName.topPrivateDomain().toString());
        }

	}

}

Expected Behavior

s3-eu-west-1.amazonaws.com hasPublicSuffix
topPrivateDomain: amazonaws.com

Actual Behavior

s3-eu-west-1.amazonaws.com hasPublicSuffix
Exception in thread "main" java.lang.IllegalStateException: Not under a public suffix: s3-eu-west-1.amazonaws.com
at com.google.common.base.Preconditions.checkState(Preconditions.java:604)
at com.google.common.net.InternetDomainName.topPrivateDomain(InternetDomainName.java:466)
at de.swr.online.GuavaTest.main(GuavaTest.java:13)

Packages

No response

Platforms

Java 8, Java 11, Java 17

Checklist

@kindlerm1958 kindlerm1958 added the type=defect Bug, not working as expected label Apr 11, 2024
@kindlerm1958 kindlerm1958 changed the title InternetDomainName.topPrivateDomain() throws exception for Amazoaws-Domain InternetDomainName.topPrivateDomain() throws exception for Amazonaws-Domain Apr 11, 2024
@cpovirk
Copy link
Member

cpovirk commented Apr 11, 2024

s3-eu-west-1.amazonaws.com is itself a public suffix, so it does not have a private domain.

@cpovirk cpovirk closed this as completed Apr 11, 2024
@kindlerm1958
Copy link
Author

I see.
So it is not safe to do the following (as we currently do):
if (domainName.hasPublicSuffix()) {
return domainName.topPrivateDomain().toString();
}
?
We will have to check wheter domainName IS a pubic suffix not just whether it has one?

@cpovirk
Copy link
Member

cpovirk commented Apr 11, 2024

If you want to know whether topPrivateDomain() is safe to call, then the method to call is isUnderPublicSuffix(), rather than hasPublicSuffix().

@kindlerm1958
Copy link
Author

Thanks a lot! Now it works as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type=defect Bug, not working as expected
Projects
None yet
Development

No branches or pull requests

2 participants