IBM Support

Compiling with Javac option of Rational Software Architect v7.5.x fails with "no unique maximal instance exists for type variable" error

Troubleshooting


Problem

Attempts to compile with Javac option from the JDK bin directory within IBM Rational Software Architect v7.5.x result in "no unique maximal instance exists for type variable ..." output.

Symptom

Using the default compilation mechanism of Rational Software Architect v7.5.x works as expected, but compiling with Javac option fails.


Steps to reproduce:
  1. Use the following source code


    public class GenericsTest2 {

       public static void main(String[] args) throws Exception {
           Integer i = readObject(args[0]);
           System.out.println(i);
       }

       public static <T> T readObject(String file) throws Exception {
           return readObject(new ObjectInputStream(new
    fileInputStream(file)));
           // closing the stream in finally removed to get a small example
       }

       @SuppressWarnings("unchecked")
       public static <T> T readObject(ObjectInputStream stream) throws Exception {
           return (T)stream.readObject();
       }
    }


  2. Compile using command line option

    C:\Program Files\IBM\SDP\jdk\bin\javac.exe GenericsTest2.java

Expected result:
Compiled GenericsTest2.class file

Actual result:
The following exception is produced:


type parameters of T cannot be determined; no unique maximal instance exists for type variable T with upper bounds T, java.lang.Object return readObject(new ObjectInputStream(new FileInputStream(file)));

Cause

This issue has been identified as a product defect and has been logged under APAR PM19633.

Resolving The Problem

WORKAROUND


Change the above code sample as shown below:


    ...

   public static <T> T readObject(String file) throws Exception {
       return
(T) readObject(new ObjectInputStream(new
fileInputStream(file)));
   
   ...


The explicit cast to type T will enable compilation of the code with the following warning message:



    GenericsTest2.java:12: warning: [unchecked] unchecked cast
    found   : java.lang.Object
    required: T
    return (T) readObject(new ObjectInputStream(new FileInputStream(file)));
    1 warning
[{"Product":{"code":"SS4JE2","label":"Rational Software Architect Standard Edition"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Java Development","Platform":[{"code":"PF033","label":"Windows"}],"Version":"7.5;7.5.1;7.5.2;7.5.3;7.5.4;7.5.5;7.5.5.1","Edition":"","Line of Business":{"code":"LOB36","label":"IBM Automation"}},{"Product":{"code":"SS4JCV","label":"Rational Software Architect for WebSphere Software"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Java Development","Platform":[{"code":"PF033","label":"Windows"}],"Version":"7.5;7.5.1;7.5.2;7.5.3;7.5.4;7.5.5;7.5.5.1","Edition":"","Line of Business":{"code":"LOB15","label":"Integration"}}]

Document Information

More support for:
Rational Software Architect Standard Edition

Software version:
7.5, 7.5.1, 7.5.2, 7.5.3, 7.5.4, 7.5.5, 7.5.5.1

Operating system(s):
Windows

Document number:
141653

Modified date:
16 June 2018

UID

swg21443094