From 2e48e54c0d260b903da3b88a9d3747d9f0df19c8 Mon Sep 17 00:00:00 2001 From: Peter Feichtinger Date: Thu, 11 Aug 2016 12:52:29 +0200 Subject: Fix NullPointerException in ControlFlow constructor. An NPE would be thrown by the constructor when called with a method without code. Also clarify the documentation of a few methods. --- src/main/javassist/bytecode/analysis/ControlFlow.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/javassist/bytecode/analysis/ControlFlow.java b/src/main/javassist/bytecode/analysis/ControlFlow.java index 736299cb..0bf76a3d 100644 --- a/src/main/javassist/bytecode/analysis/ControlFlow.java +++ b/src/main/javassist/bytecode/analysis/ControlFlow.java @@ -71,6 +71,8 @@ public class ControlFlow { return new Block[size]; } }.make(minfo); + if (basicBlocks == null) + basicBlocks = new Block[0]; int size = basicBlocks.length; int[] counters = new int[size]; for (int i = 0; i < size; i++) { @@ -97,6 +99,9 @@ public class ControlFlow { /** * Returns all the basic blocks in the method body. + * + * @return an array of basic blocks, the array has length 0 if + * the method doesn't have code. */ public Block[] basicBlocks() { return basicBlocks; @@ -133,7 +138,7 @@ public class ControlFlow { * For every array element node, its index in the * array is equivalent to node.block().index(). * - * @return an array of the tree nodes, or null if the method is abstract. + * @return an array of the tree nodes, or null if the method doesn't have code. * @see Node#block() * @see Block#index() */ @@ -179,7 +184,7 @@ public class ControlFlow { * For every array element node, its index in the * array is equivalent to node.block().index(). * - * @return an array of the tree nodes, or null if the method is abstract. + * @return an array of the tree nodes, or null if the method doesn't have code. * @see Node#block() * @see Block#index() */ -- cgit v1.2.3