Maven compiled jar appears: Reason and handling scheme for the exception of type parameter of T cannot be determined

Source: Internet
Author: User
Tags stack trace tojson

Error Scenario:

Code:

public class Jsonutil {private static final Gson Gson = new Gsonbuilder (). Setdateformat ("Yyyy-mm-dd HH:mm:ss"). Create ();p Ublic static String ToJson (Object obj) {return Gson.tojson (obj);} public static <T> T Fromjson (String json, class<t> classoft) {return Gson.fromjson (JSON, classoft);} @SuppressWarnings ("unchecked") public static <T> T Fromjson (String json, Type typeoft) {return Gson.fromjson (JSON, Typeoft);}}

Compiling under local eclipse is not a problem.

Maven Compile configuration:

<plugin><groupid>org.apache.maven.plugins</groupid><artifactid>maven-compiler-plugin </artifactId><version>2.3</version><configuration><source>1.6</source>< Target>1.6</target><encoding>utf-8</encoding></configuration></plugin>

Exception information:

[ERROR] [ERROR]/opt/web/iwork_shell/release_jar_workspace/831881fe-9cbe-4444-99d9-5667fcb96263/workspace/src/main/java /COM/BJ58/BIZ/UTILITY/JSONUTIL.JAVA:[26,22] cannot determine the type parameter of T; for the type variable T with the upper limit of t,java.lang.object, there is no unique maximum instance [ERROR], [Help 1][error] [ERROR] to see the full stack trace of the errors, re-run Maven with THE-E switch. [ERROR] Re-run Maven using The-x switch to enable full debug logging. [ERROR] [ERROR] For more information on the errors and possible solutions, please read the following articles:[error] [Help 1] http://c Wiki.apache.org/confluence/display/maven/mojofailureexception
English error message:
Incompatible Types;found: ..... required: ...........

  Cause of the problem:

With Maven compiled, the JDK version has been specified as version 1.6, and it is all right to compile the package locally Mavan. The above exception information is packaged on the MAVEN packaging server. found that the JDK version on the packaging server is the jdk1.6.0_16 version, after finding the relevant information to confirm that the problem is caused by a bug in the jdk1.6.0_16 version, this is a confirmed error: Error number: 6468354, Specific error causes can be viewed: https://bugs.openjdk.java.net/browse/JDK-6468354

Workaround:

1. Strengthen the type conversion at the place of return, and you can temporarily bypass the problem

public class Jsonutil {private static final Gson Gson = new Gsonbuilder (). Setdateformat ("Yyyy-mm-dd HH:mm:ss"). Create ();p      Ublic static String ToJson (Object obj) {return Gson.tojson (obj);} public static <T> T Fromjson (String json, class<t> Classoft) {return (T) Gson.fromjson (JSON, classoft);} @SuppressWarnings ("unchecked") public static <T> T Fromjson (String JSON, Type Typeoft) {return (T) Gson.fromjson (JS On, Typeoft);}}

  2. Upgrade JDK version to the latest version of 1.6, such as when we upgrade to the JDK1.6.0_38 version, test packaging is no problem. According to the online data, the bug has been resolved in the JDK1.6.0_25 version (no pro-Test yo)

  

Maven compiled jar appears: Reason and handling scheme for the exception of type parameter of T cannot be determined

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.