• Post Reply Bookmark Topic Watch Topic
  • New Topic

HttpsURLConnection ClassCastException - Solution Does Not Work

Greg Lafrance
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've seen several posts about using the HttpsURLConnection class and getting a ClassCastException. I've seen many suggested solutions related to backward compatibility. Here is my situation that is not working, and I ask for advice on how to proceed.

Here is my code:

import java.io.*;
import java.net.*;
import javax.net.ssl.*;
import java.util.Properties;
import java.security.*;

public class SSL {
public static void main( String args[ ] ) throws IOException {
String url_string = args[0];

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

URL url = new URL(url_string);
HttpsURLConnection httpsURLConnection = (HttpsURLConnection)(url.openConnection());
catch(Exception e){
System.out.println("Exception occurred.");
System.exit( 0 );
Here is the output:

Exception occurred.

When I execute java -version I get this:

java version "1.4.2_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b03)
Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)
Here is the explanation I've seen quite often:

HttpsURLConnection migrated to javax.net.ssl from com.sun.net.ssl for 1.4. You're probably getting an instance of this class (javax.net.ssl) instead of what you originally compiled under (com.sun.net.ssl.

But I am compiling using java 1.4.2, so why am I getting a com.sun.net.ssl.internal.www.protocol.https.DelegateHttpsURLConnection

It seems like I am locked out of using HTTPS in Java.

Do I need to reinstall my JDK?

Any help would be greatly appreciated !

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!