0

I'm trying to compile a java code from Java 1.8 to Java 18 but I'm getting the error the type sun.net is not accessible

I've read some stuff online that sun.* cannot be used anymore. Is this related to this problem? If not are there any workarounds on this error?

P.S. I'm trying to use the HttpClient class

  • it's quite possible that some packages were renamed or removed. This is one of the reasons why you shouldn't make such huge updates. From 8 to 11, that I might understand, but from 8 straight to 18? This means there are 10 version changes that all may have such removals/renames to deal withµ – Stultuske May 05 '22 at 05:59
  • 2
    There has been a warning in the Javadoc for at least 26 years telling you not to use `sun.*` classes. You should use [`java.net.http.HttpClient`](https://docs.oracle.com/en/java/javase/12/docs/api/java.net.http/java/net/http/HttpClient.html) since Java 11, and no code should ever have used `sun.net.* directly: it was never necessary. – user207421 May 05 '22 at 06:32
  • Thank you, I'm new to Java and have a project to migrate a web app written on 2006 to the latest Java version. This is the first time that I was made aware of this. – Ron Hernandez May 10 '22 at 05:59

1 Answers1

3

Quote from Oracle:

A Java program that directly calls into sun.* packages is not guaranteed to work on all Java-compatible platforms. In fact, such a program is not guaranteed to work even in future versions on the same platform.

To solve the issue, you will have to find the alternative to each missing class and replace it.

Source: Why Developers Should Not Write Programs That Call 'sun' Packages

Alexandru Severin
  • 6,021
  • 11
  • 48
  • 71