2828 * http://plantuml.com/plantuml
2929 */
3030public class ControlFlowGraphPlantUMLWriter {
31+ protected static final int MAX_OFFSET = Integer .MAX_VALUE ;
32+
3133 //protected static final String PLANTUML_URL_PREFIX = "http://plantuml.com/plantuml/png/";
3234 protected static final String PLANTUML_URL_PREFIX = "http://plantuml.com/plantuml/svg/" ;
3335 protected static final char [] PLANTUML_ENCODE_6_BIT = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_" .toCharArray ();
@@ -82,11 +84,13 @@ public static String write(ControlFlowGraph cfg) {
8284
8385 Method method = cfg .getMethod ();
8486
85- for (BasicBlock basicBlock : list )
87+ for (BasicBlock basicBlock : list ) {
8688 writeState (sb , method , basicBlock );
89+ }
8790
88- for (BasicBlock basicBlock : list )
91+ for (BasicBlock basicBlock : list ) {
8992 writeLink (sb , basicBlock );
93+ }
9094
9195 return sb .toString ();
9296 }
@@ -112,17 +116,19 @@ protected static void search(HashSet<BasicBlock> set, BasicBlock basicBlock) {
112116 case TYPE_SWITCH :
113117 search (set , basicBlock .getNext ());
114118 case TYPE_SWITCH_DECLARATION :
115- for (SwitchCase switchCase : basicBlock .getSwitchCases ())
119+ for (SwitchCase switchCase : basicBlock .getSwitchCases ()) {
116120 search (set , switchCase .getBasicBlock ());
121+ }
117122 break ;
118123 case TYPE_TRY :
119124 case TYPE_TRY_JSR :
120125 case TYPE_TRY_ECLIPSE :
121126 search (set , basicBlock .getSub1 ());
122127 case TYPE_TRY_DECLARATION :
123128 search (set , basicBlock .getNext ());
124- for (BasicBlock .ExceptionHandler exceptionHandler : basicBlock .getExceptionHandlers ())
129+ for (BasicBlock .ExceptionHandler exceptionHandler : basicBlock .getExceptionHandlers ()) {
125130 search (set , exceptionHandler .getBasicBlock ());
131+ }
126132 break ;
127133 case TYPE_IF :
128134 search (set , basicBlock .getCondition ());
@@ -144,6 +150,10 @@ protected static void search(HashSet<BasicBlock> set, BasicBlock basicBlock) {
144150 }
145151
146152 protected static void writeState (StringBuilder sb , Method method , BasicBlock basicBlock ) {
153+ if (basicBlock .getFromOffset () > MAX_OFFSET ) {
154+ return ;
155+ }
156+
147157 String id = getStateId (basicBlock );
148158
149159 switch (basicBlock .getType ()) {
@@ -300,6 +310,10 @@ protected static void writeStateEnd(StringBuilder sb, String id, BasicBlock basi
300310 }
301311
302312 protected static void writeLink (StringBuilder sb , BasicBlock basicBlock ) {
313+ if (basicBlock .getFromOffset () > MAX_OFFSET ) {
314+ return ;
315+ }
316+
303317 String id = getStateId (basicBlock );
304318
305319 switch (basicBlock .getType ()) {
@@ -399,6 +413,10 @@ protected static void writeLink(StringBuilder sb, BasicBlock basicBlock) {
399413 }
400414
401415 protected static void writeLink (StringBuilder sb , String fromId , BasicBlock to , String label ) {
416+ if (to .getFromOffset () > MAX_OFFSET ) {
417+ return ;
418+ }
419+
402420 if (to == SWITCH_BREAK ) {
403421 sb .append ("state \" SWITCH_BREAK\" as switch_break_" ).append (fromId ).append ('\n' );
404422 sb .append (fromId ).append (" --> switch_break_" ).append (fromId ).append (" : " ).append (label ).append ('\n' );
0 commit comments