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

Compilation error with Java 17 #1

Closed
sehenor opened this issue Aug 10, 2023 · 1 comment
Closed

Compilation error with Java 17 #1

sehenor opened this issue Aug 10, 2023 · 1 comment

Comments

@sehenor
Copy link

sehenor commented Aug 10, 2023

Since this is a very useful tool, and this solution is even listed by Atlassian as a good improvement to their original version of SSLPoke I thought it was worth reporting this issue.
I get the following compilation error when compiling with Java 17.

% java --version
openjdk 17.0.7 2023-04-18
OpenJDK Runtime Environment Temurin-17.0.7+7 (build 17.0.7+7)
OpenJDK 64-Bit Server VM Temurin-17.0.7+7 (build 17.0.7+7, mixed mode, sharing)
% javac SSLPoke.java
SSLPoke.java:71: error: package sun.net.www.protocol.http is not visible
                     + "User-Agent: " + sun.net.www.protocol.http.HttpURLConnection.userAgent + "\r\n"
                                                            ^
  (package sun.net.www.protocol.http is declared in module java.base, which does not export it to the unnamed module)
1 error`

According to this answer on Stack Overflow (https://stackoverflow.com/questions/10782957/what-to-use-instead-of-sun-net-www-protocol-http-httpurlconnection-useragent) I made the below changes that worked for me.

    private static void open_http_connect_tunnel(Socket tunnel, String tunnel_host, int tunnel_port, String host, int port)
    throws IOException
    {
        OutputStream out = tunnel.getOutputStream();
        String javaVersion = "Java/" + System.getProperty("java.version");
        String userAgent = System.getProperty("http.agent") == null ? javaVersion : System.getProperty("http.agent") + " " + javaVersion;
        String msg = "CONNECT " + host + ":" + port + " HTTP/1.1\n"
                     + "User-Agent: " + userAgent + "\r\n"
                     + "\r\n";
gebi added a commit that referenced this issue Oct 18, 2023
@gebi
Copy link
Owner

gebi commented Oct 18, 2023

awesome, thx for your fix, integrated it an now it compiles for java 11/17 and 21 :), THX!

% make test
/usr/lib/jvm/java-11-openjdk-amd64/bin/javac SSLPoke.java
/usr/lib/jvm/java-17-openjdk-amd64/bin/javac SSLPoke.java
/usr/lib/jvm/java-21-openjdk-amd64/bin/javac SSLPoke.java
%

@gebi gebi closed this as completed Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants