rpau / javalang-compiler

Java compiler elements (symbol and type tables) to perform code semantic analysis
GNU Lesser General Public License v3.0
10 stars 4 forks source link

Exception on swing class ressolution #11

Open rpau opened 8 years ago

rpau commented 8 years ago

ERROR [main] - TRANSFORMATION CHAIN (default) FAILS An exeception has been produced during the null transformation - org.walkmod.util.location.LocationImpl@1d5f07df at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.walkmod.walkers.AbstractWalker.walk(AbstractWalker.java:250) at org.walkmod.walkers.AbstractWalker.execute(AbstractWalker.java:265) at org.walkmod.javalang.walkers.DefaultJavaWalker.execute(DefaultJavaWalker.java:158) at org.walkmod.impl.DefaultChainWalkerInvocation.invoke(DefaultChainWalkerInvocation.java:41) at org.walkmod.impl.DefaultChainInvocation.invoke(DefaultChainInvocation.java:38) at org.walkmod.impl.DefaultChainAdapter.execute(DefaultChainAdapter.java:165) at org.walkmod.WalkModFacade.executeAllChains(WalkModFacade.java:911) at org.walkmod.WalkModFacade.apply(WalkModFacade.java:376) at org.walkmod.commands.ApplyCommand.execute(ApplyCommand.java:40) at org.walkmod.WalkModDispatcher.execute(WalkModDispatcher.java:171) at org.walkmod.WalkModDispatcher.main(WalkModDispatcher.java:196) Caused by: java.lang.reflect.InvocationTargetException ... 14 more Caused by: java.lang.VerifyError: Bad type on operand stack Exception Details: Location: javax/swing/JFrame.getAccessibleContext()Ljavax/accessibility/AccessibleContext; @16: putfield Reason: Type 'javax/swing/JFrame$AccessibleJFrame' (current frame, stack[1]) is not assignable to 'javax/accessibility/AccessibleContext' Current Frame: bci: @16 flags: { } locals: { 'javax/swing/JFrame' } stack: { 'javax/swing/JFrame', 'javax/swing/JFrame$AccessibleJFrame' } Bytecode: 0x0000000: 2ab4 0005 c700 0f2a bb00 6659 2ab7 0067 0x0000010: b500 052a b400 05b0
Stackmap Table: same_frame(@19)

at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
at java.lang.Class.getDeclaredFields(Class.java:1916)
at org.walkmod.javalang.compiler.reflection.FieldInspector.getNonPrivateFields(FieldInspector.java:39)
at org.walkmod.javalang.compiler.actions.LoadFieldDeclarationsAction$FieldsPopulator.loadFieldsFromClass(LoadFieldDeclarationsAction.java:199)
at org.walkmod.javalang.compiler.actions.LoadFieldDeclarationsAction$FieldsPopulator.loadExtendsOrImplements(LoadFieldDeclarationsAction.java:178)
at org.walkmod.javalang.compiler.actions.LoadFieldDeclarationsAction$FieldsPopulator.visit(LoadFieldDeclarationsAction.java:107)
at org.walkmod.javalang.compiler.actions.LoadFieldDeclarationsAction$FieldsPopulator.visit(LoadFieldDeclarationsAction.java:73)
at org.walkmod.javalang.ast.body.ClassOrInterfaceDeclaration.accept(ClassOrInterfaceDeclaration.java:134)
at org.walkmod.javalang.compiler.actions.LoadFieldDeclarationsAction.doPush(LoadFieldDeclarationsAction.java:67)
at org.walkmod.javalang.compiler.symbols.SymbolAction.execute(SymbolAction.java:25)
at org.walkmod.javalang.compiler.symbols.Symbol.invokeActions(Symbol.java:144)
at org.walkmod.javalang.compiler.symbols.SymbolTable.invokeActions(SymbolTable.java:201)
at org.walkmod.javalang.compiler.symbols.SymbolTable.pushSymbol(SymbolTable.java:342)
at org.walkmod.javalang.compiler.symbols.SymbolTable.pushSymbol(SymbolTable.java:283)
at org.walkmod.javalang.compiler.types.ScopeLoader.process(ScopeLoader.java:99)
at org.walkmod.javalang.compiler.types.ScopeLoader.visit(ScopeLoader.java:116)
at org.walkmod.javalang.compiler.types.ScopeLoader.visit(ScopeLoader.java:43)
at org.walkmod.javalang.ast.body.ClassOrInterfaceDeclaration.accept(ClassOrInterfaceDeclaration.java:128)
at org.walkmod.javalang.compiler.symbols.SymbolVisitorAdapter.visit(SymbolVisitorAdapter.java:169)
rpau commented 8 years ago

http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8006684

cal101 commented 8 years ago

I don't think it's related to that bug. I suspect a classloader issue that those classes are loaded by different class loaders and especially that the super class of AccessibleJFrame is loaded by a different class loader than javax/accessibility/AccessibleContext class used here.

cal101 commented 8 years ago

Here some class loaders involved. Note sure how to interpret that.

              } catch (VerifyError e) {
            System.out.println("clazz " + clazz.getName() + " class loader: " + clazz.getClassLoader());
            final Class<?> superclass = clazz.getSuperclass();
            if (superclass != null) {
                System.out.println("superclazz " + superclass.getName() + " class loader: " + superclass.getClassLoader());
            }
            System.out.println("AccessibleContext class loader: " +  AccessibleContext.class.getClassLoader());
            throw e;
        }
clazz javax.swing.JOptionPane class loader: org.walkmod.rawclasspath.providers.RawClasspathProvider$1@20ccf40b
superclazz javax.swing.JComponent class loader: org.walkmod.rawclasspath.providers.RawClasspathProvider$1@20ccf40b
AccessibleContext class loader: null
cal101 commented 8 years ago
package de.walkmod.classloader;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class VerifyError {
    public void m() throws Exception {
        BufferedImage image = ImageIO.read(new ByteArrayInputStream("no-image".getBytes()));
        JOptionPane.showMessageDialog(null,null,"title",JOptionPane.ERROR_MESSAGE,new ImageIcon(image));
    }
}

results:

Error processing the analysis of [.../src/main/java/de/walkmod/classloader/VerifyError.java] - [-1:-1]
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
    at java.lang.Class.getDeclaredField(Class.java:2068)
    at org.walkmod.javalang.compiler.reflection.FieldInspector.findFieldType(FieldInspector.java:72)
    at org.walkmod.javalang.compiler.types.TypeVisitorAdapter.visit(TypeVisitorAdapter.java:347)
    at org.walkmod.javalang.compiler.types.TypeVisitorAdapter.visit(TypeVisitorAdapter.java:115)
    at org.walkmod.javalang.ast.expr.FieldAccessExpr.accept(FieldAccessExpr.java:114)
    at org.walkmod.javalang.compiler.types.TypeVisitorAdapter.visit(TypeVisitorAdapter.java:402)
    at org.walkmod.javalang.compiler.types.TypeVisitorAdapter.visit(TypeVisitorAdapter.java:115)
    at org.walkmod.javalang.ast.expr.MethodCallExpr.accept(MethodCallExpr.java:138)
    at org.walkmod.javalang.compiler.symbols.SymbolVisitorAdapter.visit(SymbolVisitorAdapter.java:723)
    at org.walkmod.javalang.compiler.symbols.SymbolVisitorAdapter.visit(SymbolVisitorAdapter.java:92)
    at org.walkmod.javalang.ast.stmt.ExpressionStmt.accept(ExpressionStmt.java:79)
    at org.walkmod.javalang.visitors.VoidVisitorAdapter.visit(VoidVisitorAdapter.java:203)
    at org.walkmod.javalang.compiler.symbols.SymbolVisitorAdapter.visit(SymbolVisitorAdapter.java:522)
    at org.walkmod.javalang.compiler.symbols.SymbolVisitorAdapter.visit(SymbolVisitorAdapter.java:92)
    at org.walkmod.javalang.ast.stmt.BlockStmt.accept(BlockStmt.java:89)
    at org.walkmod.javalang.visitors.VoidVisitorAdapter.visit(VoidVisitorAdapter.java:564)
    at org.walkmod.javalang.compiler.symbols.SymbolVisitorAdapter.visit(SymbolVisitorAdapter.java:550)
    at org.walkmod.javalang.compiler.symbols.SymbolVisitorAdapter.visit(SymbolVisitorAdapter.java:92)
    at org.walkmod.javalang.ast.body.MethodDeclaration.accept(MethodDeclaration.java:207)
    at org.walkmod.javalang.compiler.symbols.SymbolVisitorAdapter.visit(SymbolVisitorAdapter.java:445)
    at org.walkmod.javalang.compiler.symbols.SymbolVisitorAdapter.visit(SymbolVisitorAdapter.java:92)
    at org.walkmod.javalang.ast.body.ClassOrInterfaceDeclaration.accept(ClassOrInterfaceDeclaration.java:136)
    at org.walkmod.javalang.compiler.symbols.SymbolVisitorAdapter.visit(SymbolVisitorAdapter.java:174)
    at org.walkmod.javalang.walkers.DefaultJavaWalker.visit(DefaultJavaWalker.java:198)
    at org.walkmod.javalang.walkers.DefaultJavaWalker.accept(DefaultJavaWalker.java:86)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.walkmod.walkers.AbstractWalker.walk(AbstractWalker.java:261)
    at org.walkmod.walkers.AbstractWalker.execute(AbstractWalker.java:276)
    at org.walkmod.javalang.walkers.DefaultJavaWalker.execute(DefaultJavaWalker.java:160)
    at org.walkmod.impl.DefaultChainWalkerInvocation.invoke(DefaultChainWalkerInvocation.java:41)
    at org.walkmod.impl.DefaultChainInvocation.invoke(DefaultChainInvocation.java:38)
    at org.walkmod.impl.DefaultChainAdapter.execute(DefaultChainAdapter.java:165)
    at org.walkmod.WalkModFacade.executeAllChains(WalkModFacade.java:911)
    at org.walkmod.WalkModFacade.apply(WalkModFacade.java:376)
    at org.walkmod.commands.ApplyCommand.execute(ApplyCommand.java:40)
    at org.walkmod.WalkModDispatcher.execute(WalkModDispatcher.java:171)
    at org.walkmod.WalkModDispatcher.main(WalkModDispatcher.java:196)
Caused by: java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    javax/swing/JOptionPane.getAccessibleContext()Ljavax/accessibility/AccessibleContext; @16: putfield
  Reason:
    Type 'javax/swing/JOptionPane$AccessibleJOptionPane' (current frame, stack[1]) is not assignable to 'javax/accessibility/AccessibleContext'
  Current Frame:
    bci: @16
    flags: { }
    locals: { 'javax/swing/JOptionPane' }
    stack: { 'javax/swing/JOptionPane', 'javax/swing/JOptionPane$AccessibleJOptionPane' }
  Bytecode:
    0x0000000: 2ab4 00ef c700 0f2a bb00 f059 2ab7 00f1
    0x0000010: b500 ef2a b400 efb0                    
  Stackmap Table:
    same_frame(@19)

    ... 42 more
rpau commented 8 years ago

Great :+1:

cal101 commented 8 years ago

Most people won't call it "Great" having to deal with class loader issues. ;-)

rpau commented 8 years ago

I am an exception in many things :P

kstarsinic commented 7 years ago

I am getting a similar error when trying to run walkmod on one of my projects (throws VerifyError; Type 'javax/swing/JDialog$AccessibleJDialog' is not assignable to 'javax/accessibility/AccessibleContext'). Can you offer some clues on working around this?