nhatminhle / cofoja

Contracts for Java
GNU Lesser General Public License v3.0
151 stars 18 forks source link

When using contracts in java.lang classes, you get NPE when debugging the contracts #7

Open nhatminhle opened 9 years ago

nhatminhle commented 9 years ago

From alexl...@gmail.com on August 13, 2011 07:28:38

What steps will reproduce the problem? I have started some tests to instrument java.lang classes in the bootclasspath and I noticed that when you try to turn on the debug output for contracts, you get an NPE since the System.err variable may not yet be set when the first contract is checked (I have tried to add a contract to StringBuilder and that causes the NPE) What version of the product are you using? On what operating system? I am using cofoja r138 . Please provide any additional information below. The fix simply ignores the debug messages if err is not yet available, so actually print the messages it would be necessary to buffer the messages and print them when the err stream becomes available.

public static void contractInfo(String message) { if (isLoggingEnabled("contract")) { if(System.err!=null) { System.err.println("[com.google.java.contract:contract "

Original issue: http://code.google.com/p/cofoja/issues/detail?id=33