bugKawa - Bugs: bug #42713, ...

 
 

bug #42713: MalformedParameterizedTypeException thrown when compiling

Submitter:  Matthieu Vachon <maoueh>
Submitted:  Wed 09 Jul 2014 02:35:40 AM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  bothner
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 10 Jul 2014 04:58:26 PM UTC, comment #5: 


> As far as I can tell, it's not actually malformed. Rather the issue appears to be that Kawa can't access teh classes involved.


I think I might have understand the problem. The following java snippet fails with MalformedException:


    public static void main(String[] args) {
        Class clazz = ResourcesPlugin.class;
        Field[] fields = clazz.getDeclaredFields();
        Field field = fields[33];

        field.getGenericType();
    }


But this one fails with `error: type ServiceRegistration does not take parameters`:


public class TestParameterizedType {
    public static class Service {
        private ServiceRegistration<IWorkspace> workspaceRegistration;
    }
}


It appears that `ResourcesPlugin` was compiled with Java5 while `ServiceRegistration` with Java4. Hence, this might explain why the call to `getGenericType` fails when trying to access `ServiceRegistration` generic type.

I'm not sure I understand the reasoning with the permission check. What kind of permission would Kawa check exactly?

Matthieu Vachon <maoueh>
Thu 10 Jul 2014 03:45:46 PM UTC, comment #4: 


> It sure it ain't Kawa faults if the class is malformed, but Kawa should deal with it the best it can.


As far as I can tell, it's not actually malformed.  Rather the issue appears to be that Kawa can't access teh classes involved.

> I don't think it's enough. It will work with this particular test case, but if another similar classes is encountered, but this time has a protected or public field, it will still fail.
> The `rfield.getGenericType()` now in `gnu/bytecode/Field.java` will still throw an exception in such potential case.


But now the exception is only thrown if you actually access the field. In which case an exception might not be out of place. Still, I agree a friendlier error message would help.

However, there is a reasonable hope that Kawa will do a permission check before it calls getType, in which case the current code is ok.

I'll think about it, but it would help if you could force an "unfriendly" exception message (rather than a "friendly" permission-failed message).

Per Bothner <bothner>
Group administrator
Thu 10 Jul 2014 03:11:43 PM UTC, comment #3: 


> The Exception was not about a kawa-generated field, but one in the Eclipse classes.


I know, I though it was clear in my first email, sorry.

> I actually checked in two fixes, either of which should work, but both make sense for performance reasons


I don't think it's enough. It will work with this particular test case, but if another similar classes is encountered, but this time has a protected or public field, it will still fail.

The `rfield.getGenericType()` now in `gnu/bytecode/Field.java` will still throw an exception in such potential case.

It sure it ain't Kawa faults if the class is malformed, but Kawa should deal with it the best it can.

The call to `getGenericType` should be wrap in a try/catch to traps `MalformedParameterizedTypeException` and act accordingly when it happens. When such exception is raised, Kawa could assume the field is not generic, assume the field's generic type is Object or stop compilation with a more "user-friendly" message.



Matthieu Vachon <maoueh>
Thu 10 Jul 2014 02:41:06 PM UTC, comment #2: 

The Exception was not about a kawa-generated field, but one in the Eclipse classes.  As far as I can tell, it's not really a "malformed parameterized type".  I'm guessing the problem might be related access-permissions issue - for one thing, the field itself is private, so it's silly to resolve its type.

I actually checked in two fixes, either of which should work, but both make sense for performance reasons:
(1) Make the call getGenericType lazy -i.e. defer until getType is called.
(2) skip private fields (which the documentation states, but we didn't do).

Per Bothner <bothner>
Group administrator
Wed 09 Jul 2014 02:45:52 AM UTC, comment #1: 

I'm completely unable to attach the archive to the bug report. No error message appears but after submit, the archive is never attached.

I uploaded it to my Google drive account, here the link:

https://drive.google.com/file/d/0B_zzArQGaVwQSjMwbW55YndpWGc/edit?usp=sharing

Then `File > Download` (or simply Ctrl+S) to download archive.




Matthieu Vachon <maoueh>
Wed 09 Jul 2014 02:35:40 AM UTC, original submission:  

When compiling this simple test case, the compiler throws a `java.lang.reflect.MalformedParameterizedTypeException`:

;; testcase.scm
(static-field <org.eclipse.core.resources.ResourcesPlugin> 'PI_RESOURCES)

The offending field in class `org.eclipse.core.resources.ResourcesPlugin` is `private
ServiceRegistration<IWorkspace> workspaceRegistration`.

The attached archive contains the following content for reproducing this bug:

  • testcase.scm - Simple test case to compile.
  • testcase.sh - Bash script setuping the classpath.
  • *.jar - The Eclipse jars required for compilation.
  • *.class - The compiled class files extracted from the jars.
  • *.java - The source file for the extracted class files.


Classes `IWorkspace` and `ResourcesPlugin` comes from `org.eclipse.core.resources.jar` and `ServiceRegistration` from `org.eclipse.osgi.jar`.

Tell me if you need anything else.

The full exception stack trace is the following:


$ sh testcase.sh
(compiling testcase.scm to testcase)
testcase.scm:1:1: caught exception in inliner for #<procedure static-field> - java.lang.reflect.MalformedParameterizedTypeException
    sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:42)
    sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:35)
    sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:77)
    sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:86)
    sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:122)
    sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)
    sun.reflect.generics.repository.FieldRepository.getGenericType(FieldRepository.java:67)
    java.lang.reflect.Field.getGenericType(Field.java:223)
    gnu.bytecode.ClassType.addField(ClassType.java:620)
    gnu.bytecode.ClassType.addFields(ClassType.java:649)
    gnu.bytecode.ClassType.getFields(ClassType.java:529)
    gnu.bytecode.ClassType.getDeclaredField(ClassType.java:543)
    gnu.bytecode.ClassType.getField(ClassType.java:562)
    gnu.kawa.reflect.SlotGet.lookupMember(SlotGet.java:227)
    gnu.kawa.reflect.CompileReflect.validateApplySlotGet(CompileReflect.java:152)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    gnu.expr.InlineCalls.maybeInline(InlineCalls.java:839)
    gnu.expr.QuoteExp.validateApply(QuoteExp.java:164)
    gnu.expr.ReferenceExp.validateApply(ReferenceExp.java:203)
    gnu.kawa.functions.CompilationHelpers.validateApplyToArgs(CompilationHelpers.java:75)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    gnu.expr.InlineCalls.maybeInline(InlineCalls.java:839)
    gnu.expr.QuoteExp.validateApply(QuoteExp.java:164)
    gnu.expr.ReferenceExp.validateApply(ReferenceExp.java:203)
    gnu.expr.InlineCalls.visitApplyExp(InlineCalls.java:173)
    gnu.expr.InlineCalls.visitApplyExp(InlineCalls.java:37)
    gnu.expr.ApplyExp.visit(ApplyExp.java:525)
    gnu.expr.ExpVisitor.visit(ExpVisitor.java:52)
    gnu.expr.InlineCalls.visit(InlineCalls.java:63)
    gnu.expr.InlineCalls.visit(InlineCalls.java:37)
    gnu.expr.LambdaExp.visitChildrenOnly(LambdaExp.java:1645)
    gnu.expr.LambdaExp.visitChildren(LambdaExp.java:1634)
    gnu.expr.InlineCalls.visitScopeExp(InlineCalls.java:460)
    gnu.expr.InlineCalls.visitLambdaExp(InlineCalls.java:642)
    gnu.expr.InlineCalls.visitLambdaExp(InlineCalls.java:37)
    gnu.expr.ExpVisitor.visitModuleExp(ExpVisitor.java:96)
    gnu.expr.InlineCalls.visitModuleExp(InlineCalls.java:501)
    gnu.expr.InlineCalls.visitModuleExp(InlineCalls.java:37)
    gnu.expr.ModuleExp.visit(ModuleExp.java:484)
    gnu.expr.ExpVisitor.visit(ExpVisitor.java:52)
    gnu.expr.InlineCalls.visit(InlineCalls.java:63)
    gnu.expr.InlineCalls.inlineCalls(InlineCalls.java:47)
    gnu.expr.Compilation.process(Compilation.java:1988)
    gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:309)
    gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:290)
    gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:290)
    gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:290)
    kawa.repl.compileFiles(repl.java:819)
    kawa.repl.processArgs(repl.java:443)
    kawa.repl.main(repl.java:866)


Matt

Matthieu Vachon <maoueh>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bothner (Posted a comment)
  • -email is unavailable- added by maoueh (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-07-31 bothner Open/ClosedOpen Closed
    2014-07-10 bothner Open/ClosedClosed Open
    2014-07-10 bothner StatusNone Fixed
        Assigned toNone bothner
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code