001/* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016package org.opengion.fukurou.system; 017 018import java.util.List; // 6.9.2.1 (2018/03/12) 019import java.util.ArrayList; // 6.9.2.1 (2018/03/12) 020import java.util.Set; // 6.9.2.1 (2018/03/12) 021import java.util.HashSet; // 6.9.2.1 (2018/03/12) 022 023import java.util.concurrent.ConcurrentMap; // 6.4.3.3 (2016/03/04) 024import java.util.concurrent.ConcurrentHashMap; 025 026import static org.opengion.fukurou.system.HybsConst.CR; // 6.1.0.0 (2014/12/26) refactoring 027import static org.opengion.fukurou.system.HybsConst.BUFFER_MIDDLE; // 6.4.2.0 (2016/01/29) 028 029/** 030 * ThrowUtil.java は、共通的に使用される Throwable,Exception関連メソッドを集約した、クラスです。 031 * 032 * StringUtil にあったメソッドを、こちらに移動させました。 033 * 034 * @og.group ユーティリティ 035 * 036 * @og.rev 6.4.2.0 (2016/01/29) 新規作成 037 * @og.rev 6.4.3.2 (2016/02/19) 全面書き換え 038 * 039 * @version 6.0 040 * @author Kazuhiko Hasegawa 041 * @since JDK8.0, 042 */ 043public final class ThrowUtil { 044 public static final int MIN_STACK_SIZE = 3; // 先頭から、通常にスタックトレースする行数。 045// public static final int NOMAL_STACK_SIZE = 5; // 先頭から、通常にスタックトレースする行数。 046// public static final int UNLIMITED_SIZE = -1; // スタックトレースする行数。-1 は、制限なし 047 048 // 6.9.2.1 (2018/03/12) 複数個所で呼ばれた場合の処理が、うまく出来ないので、暫定対策。(同時起動で、混ざる) 049 private static final CaseBuilder buf = new CaseBuilder(); 050 051 // 6.9.3.0 (2018/03/26) static で持ちます。 052 private static final StackTraceElement NULL_STE = new StackTraceElement( "","","",-1 ); 053 054 /** 055 * デフォルトコンストラクターをprivateにして、 056 * オブジェクトの生成をさせないようにする。 057 * 058 */ 059 private ThrowUtil() {} 060 061 /** 062 * Throwable の printStackTrace() 結果の内、opengion に関する箇所だけを文字列に変換して返します。 063 * 064 * @og.rev 6.4.2.0 (2016/01/29) StringUtil にあったメソッドを移動。 065 * @og.rev 6.4.2.0 (2016/01/29) すべてのスタックトレースを行っていたが、絞り込みます。 066 * 067 * @param th printStackTraceすべき元のThrowableオブジェクト 068 * 069 * @return Throwableの詳細メッセージ( th.printStackTrace() ) 070 */ 071 public static String ogStackTrace( final Throwable th ) { 072 return ogStackTrace( null , th ); 073 } 074 075 /** 076 * Throwable の printStackTrace() 結果の内、opengion に関する箇所だけを文字列に変換して返します。 077 * 078 * printStackTrace() すると、膨大なメッセージが表示されるため、その中の、"org.opengion" を 079 * 含む箇所だけを、抜粋します。 080 * また、同じ内容のエラーも除外します。 081 * 先頭から、MIN_STACK_SIZE 行は、元のままのメッセージを出力します。 082 * Throwable#getCause() で、再帰的に原因をさかのぼります。 083 * 084 * @og.rev 5.7.2.0 (2014/01/10) 新規作成 085 * @og.rev 6.4.2.0 (2016/01/29) StringUtil にあったメソッドを移動し、msg 引数を追加。 086 * @og.rev 6.4.3.2 (2016/02/19) (通常try-with-resources文によって)抑制された例外も出力します。 087 * @og.rev 6.5.0.1 (2016/10/21) メッセージに、BuildNumber.ENGINE_INFO を含める。 088 * @og.rev 6.9.0.1 (2018/02/05) causeの対応が中途半端だったので、修正します。 089 * @og.rev 6.9.2.1 (2018/03/12) 最小件数のbreak判定の方法を見直します。 090 * 091 * @param msg 合成したいメッセージ 092 * @param th 元のThrowableオブジェクト 093 * 094 * @return Throwableの詳細メッセージ( StackTraceElement の抜粋 ) 095 */ 096 public static String ogStackTrace( final String msg,final Throwable th ) { 097// final CaseBuilder buf = new CaseBuilder() 098 buf.init() 099 .append( "Version: " , BuildNumber.ENGINE_INFO ) // 6.5.0.1 (2016/10/21) エンジンのバージョン 100 .append( "Message: " , msg ); // 追加メッセージ 101 102 if( th != null ) { 103 // final CaseBuilder buf = new CaseBuilder() 104 // .append( "Version: " , BuildNumber.ENGINE_INFO ) // 6.5.0.1 (2016/10/21) エンジンのバージョン 105 // .append( "Message: " , msg ) // 追加メッセージ 106 // Throwable.toString() で、クラス名とメッセージを分けて、それぞれを重複チェックする。 107 buf.append( "Error : " , th.getClass().getCanonicalName() ) // クラス名 108 .append( " " , th.getLocalizedMessage() ) // メッセージ 109// .addStackTrace( th , MIN_STACK_SIZE , UNLIMITED_SIZE ); 110 .addStackTrace( th , MIN_STACK_SIZE ); // 6.9.2.1 (2018/03/12) 111 112 // 原因の Throwable 113 Throwable tmpTh = th.getCause(); 114 while( tmpTh != null ) { 115 buf.append( "Cause : " , tmpTh.getClass().getCanonicalName() ) // クラス名 116 .append( " " , tmpTh.getLocalizedMessage() ) // メッセージ 117// .addStackTrace( tmpTh , 0 , UNLIMITED_SIZE ); // 最小行は指定しない。 118 .addStackTrace( tmpTh , MIN_STACK_SIZE ); // 6.9.2.1 (2018/03/12) 119 120 tmpTh = tmpTh.getCause(); 121 } 122 123 // 6.4.3.2 (2016/02/19) (通常try-with-resources文によって)抑制された例外も出力します。 124 // このThrowable は、原因の Throwable は、求めません。 125 for( final Throwable supTh : th.getSuppressed() ) { 126 buf.append( "Suppressed : " , supTh.getClass().getCanonicalName() ) // クラス名 127 .append( " " , supTh.getLocalizedMessage() ) // メッセージ 128// .addStackTrace( supTh , 0 , UNLIMITED_SIZE ); 129 .addStackTrace( supTh , MIN_STACK_SIZE ); // 6.9.2.1 (2018/03/12) 130 } 131 } 132 133// return buf.toString(); 134 return buf.toString().trim(); 135 } 136 137 /** 138 * 発生元を示すクラス、メソッド、行番号とともに、メッセージを合成した文字列を返します。 139 * 140 * 通常、System.out.println() で済ましていたエラーメッセージに対して、 141 * エラー発生場所を特定する為の情報を付与したメッセージを作成します。 142 * 発生場所の行番号は、このメソッド(実施は、オーバーロード先)で new Throwable して、取得します。 143 * 呼ぶ場所で、new Throwable() する代わりの簡易目祖度になります。 144 * 145 * @og.rev 6.4.2.0 (2016/01/29) 新規作成。 146 * 147 * @param msg 合成したいメッセージ 148 * 149 * @return 発生元を示すクラス、メソッド、行番号とともに、メッセージを合成した文字列 150 */ 151 public static String ogThrowMsg( final String msg ) { 152 return ogThrowMsg( msg , null ); 153 } 154 155 /** 156 * 発生元を示すクラス、メソッド、行番号とともに、メッセージを合成した文字列を返します。 157 * 158 * 通常、System.out.println() で済ましていたエラーメッセージに対して、 159 * エラー発生場所を特定する為の情報を付与したメッセージを作成します。 160 * 行番号は、引数のThrowableの最初の情報のみ使用する為、通常は、このメソッドを 161 * 呼ぶ場所で、new Throwable() します。 162 * 発生クラスは、org.opengion か、org.apache.jsp.jsp を含む3行のみの簡易メッセージとします。 163 * 164 * @og.rev 6.3.6.1 (2015/08/28) 新規作成 165 * @og.rev 6.3.6.1 (2015/08/28) メッセージに、th.getLocalizedMessage() を含める。 166 * @og.rev 6.3.9.0 (2015/11/06) thのnullチェックを先に行う。 167 * @og.rev 6.4.2.0 (2016/01/29) StringUtil にあったメソッドを移動するとともに、メソッド名を、ogErrMsg → ogThrowMsg に変更。 168 * @og.rev 6.5.0.1 (2016/10/21) メッセージに、BuildNumber.ENGINE_INFO を含める。 169 * @og.rev 6.9.0.1 (2018/02/05) causeの対応が中途半端だったので、修正します。 170 * @og.rev 6.9.2.1 (2018/03/12) 最小件数のbreak判定の方法を見直します。 171 * 172 * @param msg 合成したいメッセージ 173 * @param th 元のThrowableオブジェクト 174 * 175 * @return 発生元を示すクラス、メソッド、行番号とともに、メッセージを合成した文字列 176 */ 177 public static String ogThrowMsg( final String msg,final Throwable th ) { 178// final CaseBuilder buf = new CaseBuilder() 179 buf.init() 180 .append( "Version: " , BuildNumber.ENGINE_INFO ) // 6.5.0.1 (2016/10/21) エンジンのバージョン 181 .append( "Message: " , msg ); // 追加メッセージ 182 183 if( th != null ) { 184 buf.append( "Error : " , th.getClass().getCanonicalName() ) // クラス名 185 .append( " " , th.getLocalizedMessage() ); // メッセージ 186// .addStackTrace( th , MIN_STACK_SIZE , MIN_STACK_SIZE ); 187 // .addStackTrace( th , MIN_STACK_SIZE ); // 6.9.2.1 (2018/03/12) 188 189// final Throwable cause = th.getCause(); // 原因の Throwable (1回だけ) 190// if( cause != null ) { 191// buf.append( "Cause : " , cause.getClass().getCanonicalName() ) // クラス名 192// .append( " " , cause.getLocalizedMessage() ); // メッセージ 193//// .addStackTrace( cause , MIN_STACK_SIZE , MIN_STACK_SIZE ); 194// // .addStackTrace( cause , MIN_STACK_SIZE ); // 6.9.2.1 (2018/03/12) 195// } 196 197 // 原因の Throwable 198 Throwable tmpTh = th.getCause(); 199 while( tmpTh != null ) { 200 buf.append( "Cause : " , tmpTh.getClass().getCanonicalName() ) // クラス名 201 .append( " " , tmpTh.getLocalizedMessage() ); // メッセージ 202 203 tmpTh = tmpTh.getCause(); 204 } 205 206 // 6.4.3.2 (2016/02/19) (通常try-with-resources文によって)抑制された例外も出力します。 207 // このThrowable は、原因の Throwable は、求めません。 208 for( final Throwable supTh : th.getSuppressed() ) { 209 buf.append( "Suppressed : " , supTh.getClass().getCanonicalName() ) // クラス名 210 .append( " " , supTh.getLocalizedMessage() ); // メッセージ 211 } 212 } 213 214// return buf.toString(); 215 // return buf.toString().trim(); 216 return buf.toThrowMsg().trim(); 217 218// final Throwable cause = th == null ? new Throwable() : th.getCause(); // 原因の Throwable 219// final Throwable tmpTh = cause == null ? new Throwable() : cause; // 行番号取得のため、例外を発生させる。 220// 221// final CaseBuilder buf = new CaseBuilder() 222// .append( "Version: " , BuildNumber.ENGINE_INFO ) // 6.5.0.1 (2016/10/21) エンジンのバージョン 223// // Throwable.toString() で、クラス名とメッセージを分けて、それぞれを重複チェックする。 224// .append( "Error : " , tmpTh.getClass().getCanonicalName() ) // クラス名 225// .append( " " , tmpTh.getLocalizedMessage() ) // メッセージ 226// .append( "Message: " , msg ) // 追加メッセージ 227// .addStackTrace( tmpTh , MIN_STACK_SIZE , MIN_STACK_SIZE ); 228// 229// return buf.toString(); 230 } 231 232// /** 233// * このクラスが連続で呼ばれた場合のメッセージを返します。 234// * 235// * この、staticクラスは、色々な箇所で呼ばれる可能性があり、しかも、 236// * 一連のエラーで、別々に呼ばれると、メッセージが分断されます。 237// * 238// * そこで、暫定的に、連続にメッセージのみ、内部変数に設定していきます。 239// * ただし、同時に異なるエラーで呼ばれた場合には、それらのメッセージが 240// * 混在する(まざる)ので、暫定的な処置です。 241// * 242// * この呼び出しで、内部変数をクリアします。 243// * 244// * @og.rev 6.9.2.1 (2018/03/12) 連続で呼ばれた場合のメッセージを返す。 245// * 246// * @return 連続で呼ばれた場合のメッセージ 247// */ 248// public static String getLastMsg() { 249// final String rtn = buf.toString(); 250// buf.clear(); 251// 252// return rtn; 253// } 254 255 /** 256 * Throwable の getStackTrace() 結果の内、opengion に関する箇所だけのStackTraceElement配列を選別して返します。 257 * 258 * 通常、スタックトレース情報は、膨大なメッセージが含まれるため、その中の、org.opengion か、org.apache.jsp.jsp を 259 * 含む箇所だけを、抜粋します。 260 * ただし、ThrowUtilクラス(このクラス)内で、スタックトレースを new しているため、このクラスで発生した 261 * スタックトレースは、含まないようにしています。このクラスからエラーが発生しないことを望みます。 262 * 処理は、先頭から、minCnt件数までは、そのまま残し、それ以降は、関連するトレース情報のみ残します。 263 * 264 * @og.rev 6.9.2.1 (2018/03/12) 選別だけを別に用意します。 265 * 266 * @param th 元のThrowableオブジェクト(!= null 保障済み) 267 * @param minCnt StackTraceElementを登録する最小件数 268 * @return 選別されたStackTraceElement配列 269 * @see java.lang.Throwable#getStackTrace() 270 */ 271 public static StackTraceElement[] selectElement( final Throwable th , final int minCnt ) { 272// final StackTraceElement NULL_ELEMENT = new StackTraceElement( "","","",-1 ); 273 final Set<String> cacheSet = new HashSet<>(); // 同一スタックの除外用 274 275 final List<StackTraceElement> list = new ArrayList<>(); 276 277 int idx = 0; 278 for( final StackTraceElement stEle : th.getStackTrace() ) { 279 final String stkMsg = stEle.toString(); 280 if( cacheSet.contains( stkMsg ) ) { continue; } // 同じメッセージを出さない対応 281 cacheSet.add( stkMsg ); 282 283 final String cls = stEle.getClassName(); 284 285 boolean flag = true; // 連続で、出力しない。 286 if( minCnt < 0 || idx < minCnt || 287 // !cls.contains( "ThrowUtil" ) && // ここで、new Throwable しないので、判定不要。 288 ( cls.contains( "org.opengion" ) || cls.contains( "org.apache.jsp.jsp" ) ) ) { 289 list.add( stEle ); 290 flag = true; // 省略解除 291 } 292 else { 293 if( flag ) { 294// list.add( NULL_ELEMENT ); // StackTraceElementの省略 295 list.add( NULL_STE ); // StackTraceElementの省略 296 flag = false; // 連続で、出力しない。 297 } 298 } 299 idx++ ; 300 } 301 return list.toArray( new StackTraceElement[list.size()] ); 302 } 303 304 /** 305 * StringBuilder を、例外処理のスタックに特化した形で作り直した内部クラスです。 306 * 307 * printStackTrace() すると、膨大なメッセージが表示されるため、その中の、"org.opengion" と 308 * "org.apache.jsp.jsp" を含む箇所だけを、抜粋します。 309 * また、同じ内容のエラーも除外します。 310 * 311 * ※ 怪しい実装 312 * StackTrace は、内部的に、色々な箇所で呼ばれたり、同じ要因で、何度も再作成されたりします。 313 * この内部クラスも、ひとつの例外で、何度も作成されるため、重複チェックの方法を、時間制限で、 314 * 同一メッセージの重複処理を行っています。 315 * よって、まったく異なる要因のエラーが同時に発生した場合、重複処理の判定で、除外される可能性が 316 * あります。(発生場所の行番号が異なれば、重複処理されても残るので、デバッグ可能です) 317 * 318 * @og.rev 6.4.3.2 (2016/02/19) 新規追加 319 * @og.rev 6.9.2.1 (2018/03/12) 重複処理を、staticではなく、自身のオブジェクト内だけに変更します。 320 */ 321 private static final class CaseBuilder { 322 private static final String USE_KEY = "USE_KEY" ; 323 private static final long CACHE_TIME = 3000L; // Exceptionが発生した場合、連続してCallされるため、一まとめにする。 324 325// private static final ConcurrentMap<String,String> MSG_MAP = new ConcurrentHashMap<>(); // 同期Setの代わり。重複の取り除き判定 326 private final ConcurrentMap<String,String> MSG_MAP = new ConcurrentHashMap<>(); // 同期Setの代わり。重複の取り除き判定 327// private static volatile long lastCall = 0L; 328 private volatile long lastCall = 0L; 329 330// private final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE ); 331 private final List<String> list = new ArrayList<>(); 332 333 /** 334 * デフォルトコンストラクタ。 335 * 336 * 時間制限が過ぎれば、キャッシュをクリアします。 337 * 338 * @og.rev 6.4.3.2 (2016/02/19) 新規追加 339 * @og.rev 6.4.3.3 (2016/03/04) synchronized を取り除きます。 340 * @og.rev 6.9.2.1 (2018/03/12) 重複処理を、staticではなく、自身のオブジェクト内だけに変更します。 341 */ 342 public CaseBuilder() { 343// final long now = System.currentTimeMillis(); 344// if( now - lastCall > CACHE_TIME ) { // 前回キャッシュ時からの経過時刻が、CACHE_TIME を上回っている場合。 345// lastCall = now; 346// MSG_MAP.clear(); 347// } 348 } 349 350 /** 351 * 初期化します。 352 * 353 * @og.rev 6.9.2.1 (2018/03/12) 新規追加 354 * 355 * @return 自分自身 356 */ 357 public CaseBuilder init() { 358 final long now = System.currentTimeMillis(); 359 if( now - lastCall > CACHE_TIME ) { // 前回キャッシュ時からの経過時刻が、CACHE_TIME を上回っている場合。 360 lastCall = now; 361 MSG_MAP.clear(); 362// buf.setLength( 0 ); 363 list.clear(); 364 } 365 return this; 366 } 367 368 /** 369 * タイトルとメッセージを内部のStringBuilderに追記していきます。 370 * 371 * メッセージが、null や、空文字の場合は、何もしません。また、同一メッセージの追加は出来ません。 372 * 戻り値に、自分自身のオブジェクトを返すので、StringBuilder と同様に、接続できます。 373 * 374 * @og.rev 6.4.3.2 (2016/02/19) 新規追加 375 * @og.rev 6.4.3.3 (2016/03/04) 同一メッセージの判定を、trim() したキーで行います。 376 * @og.rev 6.9.2.1 (2018/03/12) タイトルがnullや空文字の場合も、なにもしません。 377 * 378 * @param title タイトルに相当します。 379 * @param msg メッセージ 380 * @return 自分自身 381 */ 382 public CaseBuilder append( final String title , final String msg ) { 383// if( msg != null && !msg.isEmpty() ) { 384 if( title != null && !title.isEmpty() && msg != null && !msg.isEmpty() ) { 385 // 超特殊処理1 386 // msg に改行コードを含む場合、最初の改行で、前後に分けて、それぞれをキャッシュ判定します。 387 // SQL文など、行が多く出る場合に、何度も繰り返されるのを避けるためです。 388 // 通常、1行目は、Exception発生元のため、異なるケースがありますが、2行目以降は、 389 // 同じケースが多いための処置です。 390 final String msg0 = msg.trim(); 391 392 // Map#putIfAbsent : 戻り値は、以前の値。追加有り、置換なし(先勝)、削除なし 393 // Map#put と何が違うかというと、置き換えが無い。速度は誤差範囲です。 394 if( MSG_MAP.putIfAbsent( msg0,USE_KEY ) == null ) { // 同期Setの代わり。未登録時は、null が戻る。 395 final int adrs = msg0.indexOf( '\n' ); // よくない判定方法 396 if( adrs < 0 ) { 397// buf.append( CR ).append( title ).append( msg0 ); 398 list.add( title + msg0 ); 399 } 400 else { 401 final String msg1 = msg0.substring( 0,adrs ).trim(); // 最初の改行で、前後に分割します。 402 final String msg2 = msg0.substring( adrs+1 ).trim(); 403 if( MSG_MAP.putIfAbsent( msg1,USE_KEY ) == null ) { 404// buf.append( CR ).append( title ).append( msg1 ); 405 list.add( title + msg1 ); 406 } 407 if( MSG_MAP.putIfAbsent( msg2,USE_KEY ) == null ) { 408// buf.append( CR ).append( title ).append( msg2 ); 409 list.add( title + msg2 ); 410 } 411 } 412 } 413 } 414 return this; 415 } 416 417 /** 418 * Throwable の getStackTrace() 結果の内、opengion に関する箇所だけのStackTraceElement配列をCaseBuilderオブジェクトに書き込みます。 419 * 420 * 通常、スタックトレース情報は、膨大なメッセージが含まれるため、その中の、org.opengion か、org.apache.jsp.jsp を 421 * 含む箇所だけを、抜粋します。 422 * ただし、ThrowUtilクラス(このクラス)内で、スタックトレースを new しているため、このクラスで発生した 423 * スタックトレースは、含まないようにしています。このクラスからエラーが発生しないことを望みます。 424 * 処理は、先頭から、MIN_STACK_SIZE 行は、元のままのメッセージを出力し、minCnt件数で、打ち切ります。 425 * minCnt が、0 か、マイナスの場合は、打ち切り制限なしです。( Integer.MAX_VALUE を指定させるのが嫌だっただけです。 ) 426 * 427 * @og.rev 6.4.2.0 (2016/01/29) 新規作成 428 * @og.rev 6.9.2.1 (2018/03/12) 選別だけを別に用意します。 429 * 430 * @param th 元のThrowableオブジェクト(!= null 保障済み) 431 * @param minCnt StackTraceElementを登録する最小件数 432 * @return 自分自身 433 * @see java.lang.Throwable#getStackTrace() 434 */ 435// public CaseBuilder addStackTrace( final Throwable th , final int minCnt , final int minCnt ) { 436 public CaseBuilder addStackTrace( final Throwable th , final int minCnt ) { 437 for( final StackTraceElement stEle : selectElement( th,minCnt ) ) { 438 if( stEle == null || "".equals( stEle.getClassName() ) ) { 439 append( " at " , "...." ); // StackTraceElement が省略されている。 440 } 441 else { 442 append( " at " , stEle.toString() ); 443 } 444 } 445 return this; 446 447// int idx = 0; 448// for( final StackTraceElement stEle : th.getStackTrace() ) { 449// final String cls = stEle.getClassName(); 450// 451// boolean flag = true; // 連続で、出力しない。 452// if( minCnt < 0 || idx < minCnt || 453// !cls.contains( "ThrowUtil" ) && 454// ( cls.contains( "org.opengion" ) || cls.contains( "org.apache.jsp.jsp" ) ) ) { 455// append( " at " , stEle.toString() ); 456// flag = true; // 省略解除 457// } 458// else { 459// if( flag ) { 460// append( " at " , "...." ); // 連続で、出力しない。 461// flag = false; 462// } 463// } 464// idx++ ; 465// 466// // // 6.9.2.1 (2018/03/12) 最小件数のbreak判定の方法を見直します。 467// // // ThrowUtil クラスは除外し、org.opengion か、org.apache.jsp.jsp のみ収集する。 468// // if( idx < minCnt || 469// // !cls.contains( "ThrowUtil" ) && 470// // ( cls.contains( "org.opengion" ) || cls.contains( "org.apache.jsp.jsp" ) ) ) { 471// // append( " at " , stEle.toString() ); 472// // } 473// // else { 474// // append( " at " , "...." ); // 最初の1回しか、出力されません。 475// // } 476// // if( minCnt > 0 && idx >= minCnt ) { break; } // minCnt 件で、処理を打ち切ります。 477// // idx++ ; 478// } 479// return this; 480 } 481 482 /** 483 * 内部のStringBuilderを、文字列に変換して返します。 484 * 485 * 出力の直前に改行コードを出しています。 486 * 487 * @og.rev 6.4.3.2 (2016/02/19) 新規追加 488 * 489 * @return 内部のStringBuilderの文字列化されたもの 490 */ 491 @Override 492 public String toString() { 493// return buf.append( CR ).toString(); 494// return buf.toString().trim(); 495 final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE ); 496 for( final String msg : list ) { 497 buf.append( CR ).append( msg ); 498 } 499 return buf.toString(); 500 } 501 502 /** 503 * 内部のStringBuilderを、文字列に変換して返します。 504 * 505 * 出力の直前に改行コードを出しています。 506 * 507 * @og.rev 6.4.3.2 (2016/02/19) 新規追加 508 * 509 * @return 内部のStringBuilderの文字列化されたもの 510 */ 511 public String toThrowMsg() { 512 final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE ); 513 for( final String msg : list ) { 514 if( ! msg.startsWith( " at " ) ) { 515 buf.append( CR ).append( msg ); 516 } 517 } 518 return buf.toString(); 519 } 520 } 521}