FAQ

Last Updated: Oct 10, 2017

Package conflict

  • Symptoms:

    An error similar to the following is reported when using OSS Java SDK:

    1. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/ssl/TrustStrategy
    2. at com.aliyun.oss.OSSClient.<init>(OSSClient.java:268)
    3. at com.aliyun.oss.OSSClient.<init>(OSSClient.java:193)
    4. at com.aliyun.oss.demo.HelloOSS.main(HelloOSS.java:77)
    5. Caused by: java.lang.ClassNotFoundException: org.apache.http.ssl.TrustStrategy
    6. at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    7. at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    8. at java.security.AccessController.doPrivileged(Native Method)
    9. at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    10. at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    11. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    12. at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    13. ... 3 more

    or

    1. Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
    2. at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
    3. at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)
    4. at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)
    5. at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:82)
    6. at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:95)
    7. at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:104)
    8. at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:62)
    9. at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:572)
    10. at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:174)
    11. at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:158)
    12. at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:149)
    13. at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:125)
    14. at com.aliyun.oss.common.comm.DefaultServiceClient.createHttpClientConnectionManager(DefaultServiceClient.java:237)
    15. at com.aliyun.oss.common.comm.DefaultServiceClient.<init>(DefaultServiceClient.java:78)
    16. at com.aliyun.oss.OSSClient.<init>(OSSClient.java:268)
    17. at com.aliyun.oss.OSSClient.<init>(OSSClient.java:193)
    18. at OSSManagerImpl.upload(OSSManagerImpl.java:42)
    19. at OSSManagerImpl.main(OSSManagerImpl.java:63)
  • Cause:

    There may be package conflicts in your project. The reason is that OSS Java SDK uses Apache httpclient 4.4.1, while your project uses Apache httpclient or commons-httpclient which conflicts with Apache httpclient 4.4.1.

  • Resolution:

    Execute mvn dependency:tree in your project directory to view the packages and version used by your project. For example, the preceding error occurs in the project because Apache httpclient 4.3 is used:

    There are two solutions to handle package conflicts:

    • Use the unified version.

      If your project uses a version in conflict with Apache httpclient 4.4.1, you should also use the 4.4.1 version. Remove the Apache httpclient dependencies of other versions in the pom.xml file. If your project uses commons-httpclient, conflicts may also occur. Please remove commons-httpclient.

    • Remove dependency conflicts.

      If your project is dependent on multiple third-party packages and the third-party package is dependent on different versions of Apache httpclient, your project may contain dependency conflicts. You should use exclusion to remove the conflicts. For more information, see Maven Guide.

The OSS Java SDK is dependent on the following versions of packages. The solution to conflicts is similar to that for httpclient and I will not repeat it here.

A package is missing

  • Symptoms:

    An error similar to the following is reported when compiling/running the OSS Java SDK:

    1. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials
    2. at com.aliyun.oss.OSSClient.<init>(OSSClient.java:268)
    3. at com.aliyun.oss.OSSClient.<init>(OSSClient.java:193)
    4. at com.aliyun.oss.demo.HelloOSS.main(HelloOSS.java:76)
    5. Caused by: java.lang.ClassNotFoundException: org.apache.http.auth.Credentials
    6. at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    7. at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    8. at java.security.AccessController.doPrivileged(Native Method)
    9. at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    10. at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    11. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    12. at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    13. ... 3 more

    or

    1. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/protocol/HttpContext
    2. at com.aliyun.oss.OSSClient.<init>(OSSClient.java:268)
    3. at com.aliyun.oss.OSSClient.<init>(OSSClient.java:193)
    4. at com.aliyun.oss.demo.HelloOSS.main(HelloOSS.java:76)
    5. Caused by: java.lang.ClassNotFoundException: org.apache.http.protocol.HttpContext
    6. at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    7. at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    8. at java.security.AccessController.doPrivileged(Native Method)
    9. at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    10. at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    11. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    12. at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    13. ... 3 more

    or

    1. Exception in thread "main" java.lang.NoClassDefFoundError: org/jdom/input/SAXBuilder
    2. at com.aliyun.oss.internal.ResponseParsers.getXmlRootElement(ResponseParsers.java:645)
    3. at
    4. at com.aliyun.oss.OSSClient.doesBucketExist(OSSClient.java:471)
    5. at com.aliyun.oss.OSSClient.doesBucketExist(OSSClient.java:465)
    6. at com.aliyun.oss.demo.HelloOSS.main(HelloOSS.java:82)
    7. Caused by: java.lang.ClassNotFoundException: org.jdom.input.SAXBuilder
    8. at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    9. at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    10. at java.security.AccessController.doPrivileged(Native Method)
    11. at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    12. at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    13. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    14. at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    15. ... 11 more
  • Cause:

    It indicates that your project lacks the required packages for compiling or running the OSS Java SDK. The OSS Java SDK is dependent on the following packages:

    • aliyun-sdk-oss-2.2.1.jar
    • hamcrest-core-1.1.jar
    • jdom-1.1.jar
    • commons-codec-1.9.jar
    • httpclient-4.4.1.jar
    • commons-logging-1.2.jar
    • httpcore-4.4.1.jar
    • log4j-1.2.15.jar

      The log4j-1.2.15.jar is optional. This package can be added when you need the logging feature. All other packages are required.

  • Resolution:

    Add packages that the OSS Java SDK is dependent on in your project through the following method:

    • If you use Eclipse, refer to Install > Method 2: Import a JAR package to your Eclipse project in the Java-SDK user manual.
    • If you use Ant, put the packages that the OSS Java SDK is dependent on into the lib directory of the project.
    • If you use javac/java directly, use -classpath/-cp to specify the path of packages that the OSS Java SDK is dependent on or put the packages that the OSS Java SDK is dependent on to the classpath path.

Connection timed out

  • Symptoms:

    The following exception is thrown during the running of the OSS Java SDK:

    1. com.aliyun.oss.ClientException: SocketException
    2. at com.aliyun.oss.common.utils.ExceptionFactory.createNetworkException(ExceptionFactory.java:71)
    3. at com.aliyun.oss.common.comm.DefaultServiceClient.sendRequestCore(DefaultServiceClient.java:116)
    4. at com.aliyun.oss.common.comm.ServiceClient.sendRequestImpl(ServiceClient.java:121)
    5. at com.aliyun.oss.common.comm.ServiceClient.sendRequest(ServiceClient.java:67)
    6. at com.aliyun.oss.internal.OSSOperation.send(OSSOperation.java:92)
    7. at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:140)
    8. at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:111)
    9. at com.aliyun.oss.internal.OSSBucketOperation.getBucketInfo(OSSBucketOperation.java:1152)
    10. at com.aliyun.oss.OSSClient.getBucketInfo(OSSClient.java:1220)
    11. at com.aliyun.oss.OSSClient.getBucketInfo(OSSClient.java:1214)
    12. at com.aliyun.oss.demo.HelloOSS.main(HelloOSS.java:94)
    13. Caused by: org.apache.http.conn.HttpHostConnectException: Connect to oss-test.oss-cn-hangzhou-internal.aliyuncs.com:80 [oss-test.oss-cn-hangzhou-internal.aliyuncs.com/10.84.135.99] failed: Connection timed out: connect
    14. at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:151)
    15. at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
    16. at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
    17. at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
    18. at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
    19. at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    20. at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
    21. at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    22. at com.aliyun.oss.common.comm.DefaultServiceClient.sendRequestCore(DefaultServiceClient.java:113)
    23. ... 9 more
  • Cause:

    Endpoint error or network connection failure.

  • Resolution:

    If the error cannot be located directly, use the OSSProbe tool for detection. OSSProbe will give possible error causes.

org.apache.http.NoHttpResponseException: The target server failed to respond

  • Symptoms:

    The following exception is thrown during the running of the OSS Java SDK:

  • Cause:

    No check on the connection validity was performed before the connection was reused. The preceding error will be triggered if an expired connection is reused.

  • Resolution:

    This is a bug in Apache httpclient 4.4. Details can be found in HTTPCLIENT-1609. The bug is fixed in 4.4.1 and later versions. Apache httpclient 4.4 is used in versions earlier than Java SDK 2.1.2, thus, the preceding issue exists. Apache httpclient 4.4.1 is used in Java SDK 2.1.2 and later versions and the issue is fixed. If this issue occurs, upgrade the OSS Java SDK to 2.1.2 or a later version.

A Java SDK call is hanging

  • Symptoms:

    If an OSS Java SDK call hangs, you can view the heap and stack through jstack -l <pid> to locate the error as shown below:

    1. "main" prio=6 tid=0x000000000291e000 nid=0xc40 waiting on condition [0x0000000002dae000]
    2. java.lang.Thread.State: WAITING (parking)
    3. at sun.misc.Unsafe.park(Native Method)
    4. - parking to wait for <0x00000007d85697f8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    5. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
    6. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
    7. at org.apache.http.pool.PoolEntryFuture.await(PoolEntryFuture.java:138)
    8. at org.apache.http.pool.AbstractConnPool.getPoolEntryBlocking(AbstractConnPool.java:306)
    9. at org.apache.http.pool.AbstractConnPool.access$000(AbstractConnPool.java:64)
    10. at org.apache.http.pool.AbstractConnPool$2.getPoolEntry(AbstractConnPool.java:192)
    11. at org.apache.http.pool.AbstractConnPool$2.getPoolEntry(AbstractConnPool.java:185)
    12. at org.apache.http.pool.PoolEntryFuture.get(PoolEntryFuture.java:107)
    13. at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:276)
    14. at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$1.get(PoolingHttpClientConnectionManager.java:263)
    15. at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:190)
    16. at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
    17. at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    18. at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
    19. at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    20. at com.aliyun.oss.common.comm.DefaultServiceClient.sendRequestCore(DefaultServiceClient.java:113)
    21. at com.aliyun.oss.common.comm.ServiceClient.sendRequestImpl(ServiceClient.java:123)
    22. at com.aliyun.oss.common.comm.ServiceClient.sendRequest(ServiceClient.java:68)
    23. at com.aliyun.oss.internal.OSSOperation.send(OSSOperation.java:94)
    24. at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:146)
    25. at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:113)
    26. at com.aliyun.oss.internal.OSSObjectOperation.getObject(OSSObjectOperation.java:229)
    27. at com.aliyun.oss.OSSClient.getObject(OSSClient.java:629)
    28. at com.aliyun.oss.OSSClient.getObject(OSSClient.java:617)
    29. at samples.HelloOSS.main(HelloOSS.java:49)
  • Cause:

    Connection leakage in the connection pool. It may be because the OSSClient.getObject was not closed after use.

  • Resolution:

    Check your project to ensure there is no connection leakage. The steps to close the connection are shown below:

    1. // Read the object
    2. OSSObject ossObject = ossClient.getObject(bucketName, key);
    3. // Use ObjectContent and ObjectMetadata
    4. // ...
    5. // Make sure to close the connection after use
    6. ossObject.getObjectContent().close();

    For detailed steps for troubleshooting hanging requests, see Troubleshoot Hang Issue.

ConnectionClosedException: Premature end of Content-Length delimited message body …

  • Symptoms:

    An error similar to the following is reported when using OSSClient.getObject:

    1. Exception in thread "main" org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 11990526; received: 202880
    2. at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:180)
    3. at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:200)
    4. at org.apache.http.impl.io.ContentLengthInputStream.close(ContentLengthInputStream.java:103)
    5. at org.apache.http.impl.execchain.ResponseEntityProxy.streamClosed(ResponseEntityProxy.java:128)
    6. at org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:228)
    7. at org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:174)
    8. at java.io.FilterInputStream.close(FilterInputStream.java:181)
    9. at java.io.FilterInputStream.close(FilterInputStream.java:181)
    10. at com.aliyun.oss.event.ProgressInputStream.close(ProgressInputStream.java:147)
    11. at java.io.FilterInputStream.close(FilterInputStream.java:181)
    12. at samples.HelloOSS.main(HelloOSS.java:39)
  • Cause:

    The interval between the two data reads exceeded one minute. The OSS will close the connection if no data is sent/received for more than one minute.

  • Resolution:

    If your app functions are: read part of the data - process the data - read the data - process the data, and the data processing duration is not fixed, we recommend that you use Specify read by range to prevent the connection from being closed during a data read.

Memory leakage

  • Symptoms:

    When the OSS Java SDK project is called and runs for a while (depending on the business volume, the runtime may range from hours to days), the memory is exhausted. Use the memory analysis tool to analyze the memory usage. Eclipse Memory Analyzer(MAT) is recommended. For its usage, see Use MAT for Heap Dump File Analysis. The analysis result is similar to the following figure, with the PoolingHttpClientConnectionManager using 96% of the memory.

    java-leaker

  • Cause:

    There may be multiple new OSSClient connections in the project, but OSSClient.shutdown is not called, leading to object leakage.

  • Resoluton:

    Make sure to use new OSSClient with OSSClient.shutdown in pairs.

The InterruptedException is thrown when OSSClient.shutdown is called

  • Symptoms:

    The following exception is thrown when OSSClient.shutdown is called:

    1. java.lang.InterruptedException: sleep interrupted
    2. at java.lang.Thread.sleep(Native Method)
    3. at com.aliyun.oss.common.comm.IdleConnectionReaper.run(IdleConnectionReaper:76)
  • Cause:

    There is a background thread from OSSClient: IdleConnectionReaper. Close idle connections regularly. If the shutdown method is called when the IdleConnectionReaper thread is asleep, the preceding exception will be thrown.

  • Resolution:

    OSS Java SDK v2.3.0 has fixed this issue. You can use the following code to ignore this exception:

    1. try {
    2. serviceClient.shutdown();
    3. } catch(Exception e) {
    4. }

Other errors

To troubleshoot other errors returned by the OSS, see Errors and troubleshooting.

Thank you! We've received your feedback.