roterdam / crystalsaf

Automatically exported from code.google.com/p/crystalsaf
0 stars 0 forks source link

Exception from enums in the CFG #28

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Exception forwarded by some MSE students. Exception is below, MSE students will 
provide the class that causes the exception. Also need to verify the version 
number of Crystal that caused this.

java.lang.ClassCastException: org.eclipse.jdt.core.dom.EnumDeclaration
cannot be cast to org.eclipse.jdt.core.dom.TypeDeclaration
at edu.cmu.cs.crystal.cfg.eclipse.EclipseCFG.visit(EclipseCFG.java:662)
at
org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:487)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2480)
at
edu.cmu.cs.crystal.cfg.eclipse.EclipseCFG.createGraph(EclipseCFG.java:188)
at edu.cmu.cs.crystal.cfg.eclipse.EclipseCFG.<init>(EclipseCFG.java:176)
at
edu.cmu.cs.crystal.cfg.eclipse.EclipseNodeFirstCFG.<init>(EclipseNodeFirstCFG.ja
va:44)
at
edu.cmu.cs.crystal.flow.worklist.AbstractWorklist.getControlFlowGraph(AbstractWo
rklist.java:63)
at
edu.cmu.cs.crystal.flow.worklist.WorklistTemplate.performAnalysis(WorklistTempla
te.java:96)
at
edu.cmu.cs.crystal.flow.MotherFlowAnalysis.performAnalysis(MotherFlowAnalysis.ja
va:464)
at
edu.cmu.cs.crystal.flow.MotherFlowAnalysis.switchToMethod(MotherFlowAnalysis.jav
a:458)
at
edu.cmu.cs.crystal.flow.MotherFlowAnalysis.performAnalysisOnSurroundingMethodIfN
eeded(MotherFlowAnalysis.java:446)
at
edu.cmu.cs.crystal.flow.MotherFlowAnalysis.getResultsOrNullBefore(MotherFlowAnal
ysis.java:128)
at
edu.cmu.cs.crystal.flow.MotherFlowAnalysis.getResultsBefore(MotherFlowAnalysis.j
ava:112)
at
edu.cmu.cs.crystal.analysis.live.LiveVariableAnalysis.analyzeMethod(LiveVariable
Analysis.java:69)
at
edu.cmu.cs.crystal.AbstractCrystalMethodAnalysis.runAnalysis(AbstractCrystalMeth
odAnalysis.java:65)
at edu.cmu.cs.crystal.internal.Crystal$1.run(Crystal.java:216)
at edu.cmu.cs.crystal.internal.Crystal$2.runJobs(Crystal.java:325)
at edu.cmu.cs.crystal.internal.Crystal.runCrystalJob(Crystal.java:135)
at edu.cmu.cs.crystal.internal.Crystal.runAnalyses(Crystal.java:127)
at
edu.cmu.cs.crystal.internal.RunCrystalHandler$1.run(RunCrystalHandler.java:62)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

Original issue reported on code.google.com by ciera.christopher on 18 Mar 2011 at 1:26

GoogleCodeExporter commented 9 years ago
I looked at EclipseCFG. Suspected problem is that the enumerator has a 
constructor, and apparently EnumDeclarations are not TypeDeclarations (lame). 
However, the problem code in trunk is on line 666 and the reporte problem is on 
line 662. I'm going to check the diff between trunk and what we have in the 
latest release to make sure this problem wasn't fixed elsewhere.

        if (node.isConstructor()) {
            TypeDeclaration type = (TypeDeclaration) node.getParent();
            for (FieldDeclaration field : type.getFields()) {
                if (!Modifier.isStatic(field.getModifiers()))
                    field.accept(this);
            }
        }

Original comment by ciera.christopher on 18 Mar 2011 at 4:03

GoogleCodeExporter commented 9 years ago
Students did not know Crystal version number, but they're using Plural 1.1.5.

Attached the problem files.

Original comment by ciera.christopher on 24 Mar 2011 at 3:31

Attachments:

GoogleCodeExporter commented 9 years ago
Indeed, problem was due to Piece having a constructor. The CFG was trying to 
access fields to do the constructor initialization, which of course an enum 
doesn't have.

Made modification to check whether the declaring type is a class first (as 
opposed to an enum or an annotation) before doing anything with fields and 
constructors. This appears to be the only place where we make that assumption.

Original comment by ciera.christopher on 24 Mar 2011 at 4:17