Author: sebb
Date: Sun Aug 23 16:52:06 2015
New Revision: 1697224

URL: http://svn.apache.org/r1697224
Log:
BCEL-253 Pass 3b verifier is too strict.

Modified:
    commons/proper/bcel/trunk/src/changes/changes.xml
    
commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/structurals/ControlFlowGraph.java
    
commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/structurals/Subroutines.java

Modified: commons/proper/bcel/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/changes/changes.xml?rev=1697224&r1=1697223&r2=1697224&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/changes/changes.xml (original)
+++ commons/proper/bcel/trunk/src/changes/changes.xml Sun Aug 23 16:52:06 2015
@@ -63,6 +63,7 @@ The <action> type attribute can be add,u
 
   <body>
     <release version="6.0" date="TBA" description="Major release with Java 7 
and 8 support">
+      <action issue="BCEL-253" type="fix">Pass 3b verifier is too 
strict.</action>
       <action issue="BCEL-248" type="fix">StackMapTable[Entry] should be 
removed and improvements merged into StackMap[Entry]</action>
       <action issue="BCEL-202" type="fix">StackMap[Table]Entry.copy() needs to 
be deep; Improved support for StackMaps</action>
       <action issue="BCEL-251" type="fix">Pass3aVerifier visitANEWARRAY() does 
not allow 255 array dimensions</action>

Modified: 
commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/structurals/ControlFlowGraph.java
URL: 
http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/structurals/ControlFlowGraph.java?rev=1697224&r1=1697223&r2=1697224&view=diff
==============================================================================
--- 
commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/structurals/ControlFlowGraph.java
 (original)
+++ 
commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/structurals/ControlFlowGraph.java
 Sun Aug 23 16:52:06 2015
@@ -409,10 +409,21 @@ public class ControlFlowGraph{
     private final Map<InstructionHandle, InstructionContext> 
instructionContexts = new HashMap<>();
 
     /** 
-     * A Control Flow Graph.
+     * A Control Flow Graph; with additional JustIce checks
+     * @param  method_gen the method generator instance
      */
     public ControlFlowGraph(MethodGen method_gen){
-        subroutines = new Subroutines(method_gen);
+        this(method_gen, true);
+    }
+
+    /** 
+     * A Control Flow Graph.
+     * @param  method_gen the method generator instance
+     * @param enableJustIceCheck if true, additional JustIce checks are 
performed
+     * @since 6.0
+     */
+    public ControlFlowGraph(MethodGen method_gen, boolean enableJustIceCheck){
+        subroutines = new Subroutines(method_gen, enableJustIceCheck);
         exceptionhandlers = new ExceptionHandlers(method_gen);
 
         InstructionHandle[] instructionhandles = 
method_gen.getInstructionList().getInstructionHandles();

Modified: 
commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/structurals/Subroutines.java
URL: 
http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/structurals/Subroutines.java?rev=1697224&r1=1697223&r2=1697224&view=diff
==============================================================================
--- 
commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/structurals/Subroutines.java
 (original)
+++ 
commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/structurals/Subroutines.java
 Sun Aug 23 16:52:06 2015
@@ -377,9 +377,20 @@ public class Subroutines{
      * Constructor.
      * @param mg A MethodGen object representing method to
      * create the Subroutine objects of.
+     * Assumes that JustIce strict checks are needed.
      */
     public Subroutines(MethodGen mg){
+        this(mg, true);
+    }
 
+    /**
+     * Constructor.
+     * @param mg A MethodGen object representing method to
+     * create the Subroutine objects of.
+     * @param enableJustIceCheck whether to enable additional JustIce checks
+     * @since 6.0
+     */
+    public Subroutines(MethodGen mg, boolean enableJustIceCheck){
         InstructionHandle[] all = 
mg.getInstructionList().getInstructionHandles();
         CodeExceptionGen[] handlers = mg.getExceptionHandlers();
 
@@ -482,22 +493,24 @@ public class Subroutines{
             }
         }
 
-        // Now make sure no instruction of a Subroutine is protected by 
exception handling code
-        // as is mandated by JustIces notion of subroutines.
-        for (CodeExceptionGen handler : handlers) {
-            InstructionHandle _protected = handler.getStartPC();
-            while (_protected != handler.getEndPC().getNext()){
-                // Note the inclusive/inclusive notation of "generic API" 
exception handlers!
-                for (Subroutine sub : subroutines.values()) {
-                    if (sub != subroutines.get(all[0])){    // We don't want 
to forbid top-level exception handlers.
-                        if (sub.contains(_protected)){
-                            throw new 
StructuralCodeConstraintException("Subroutine instruction '"+_protected+
-                                "' is protected by an exception handler, 
'"+handler+
-                                "'. This is forbidden by the JustIce verifier 
due to its clear definition of subroutines.");
+        if (enableJustIceCheck) {
+            // Now make sure no instruction of a Subroutine is protected by 
exception handling code
+            // as is mandated by JustIces notion of subroutines.
+            for (CodeExceptionGen handler : handlers) {
+                InstructionHandle _protected = handler.getStartPC();
+                while (_protected != handler.getEndPC().getNext()){
+                    // Note the inclusive/inclusive notation of "generic API" 
exception handlers!
+                    for (Subroutine sub : subroutines.values()) {
+                        if (sub != subroutines.get(all[0])){    // We don't 
want to forbid top-level exception handlers.
+                            if (sub.contains(_protected)){
+                                throw new 
StructuralCodeConstraintException("Subroutine instruction '"+_protected+
+                                    "' is protected by an exception handler, 
'"+handler+
+                                    "'. This is forbidden by the JustIce 
verifier due to its clear definition of subroutines.");
+                            }
                         }
                     }
+                    _protected = _protected.getNext();
                 }
-                _protected = _protected.getNext();
             }
         }
 


Reply via email to