-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.3.0, 1.4.0
-
generic, x86, sparc
-
generic, solaris_2.6, solaris_8, windows_nt
--
* Name: traceSample
*--------------------------------------------------------------------*/
/**
* Illustrates trace logging.
*/
public void traceSample()
{
// Entry/exit tracing is useful to see the methods that are executing.
// Knowing that something bad happened in a program is often not useful --
// unless you know how you got there!
//
// Note that the entry method is wrapped in a test of the public boolean
// "isLogging." This quick test avoids the overhead of the method call
// if tracing is off. We've given this entry a type of "public" -- a
// general public method. The entry method will add TYPE_ENTRY to
// this as a convenience to the programmer. This example shows
// that the entry method can accept additional parameters to be
// traced. These should be the parameters passed into the method
// whose entry you are tracing.
int i = 5;
String s = "This is a test";
if (trcLogger.isLogging)
trcLogger.entry(TYPE_PUBLIC, className, "traceSample",
s, new Integer(i));
// We would normally only have only one entry call in a method.
// To illustrate a few points, this methods gets more than one!
//
// This example also shows an entry trace with no parameters. If
// you have more than two parameters, you have to create an Object[],
// just as was shown for message tracing.
if (trcLogger.isLogging)
trcLogger.entry(TYPE_PUBLIC, this, "traceSample");
// Here's an example of creating an Object array of four parameters.
Object[] parms = {"a", "b", "c", "d"};
if (trcLogger.isLogging)
trcLogger.entry(TYPE_PUBLIC, className, "traceSample", parms);
// For general tracing, use the text method. You can trace any String
// that you care to build. This sample illustrates the use of trace types.
if (trcLogger.isLogging)
{
String msg = "1. Trace is valuable when Baddd Things happen to Good Code.";
trcLogger.text(TYPE_SVC, className, "traceSample", msg);
}
// Exceptions can also be traced. Note that you can test the isLogging()
// method as well as the isLogging boolean.
if (trcLogger.isLogging())
trcLogger.exception(TYPE_ERROR_EXC, this, "traceSample", new
Exception("Testing exception"));
// Here's one using a NestedException. This allows you to add your own
// message to that contained in the exception. We'll show it in a try/catch
// block, just as if you caught an exception and wished to log the error.
try
{
throw new LogException("A message in a LogException");
}
catch (LogException e)
{
NestedException ne = new NestedException("An additional message in a NestedException", e);
if (trcLogger.isLogging())
trcLogger.exception(TYPE_ERROR_EXC, className, "traceSample", ne);
// Let's do it again, but use a localized message.
MessageCatalog cat = new
MessageCatalog("com.leh.eq.util.jLog.samples.Msgs");
ne = new NestedException(cat.getMessage("STATIC"), e);
if (trcLogger.isLogging())
trcLogger.exception(TYPE_ERROR_EXC, this, "traceSample", ne);
}
// If you'd need to see the call stack, use the stackTrace method.
if (trcLogger.isLogging)
trcLogger.stackTrace(TYPE_PUBLIC, className, "traceSample");
// Here is an example of tracing an array of bytes.
byte[] data = new byte[69];
for (int j = 0; j < 69; j++)
data[j] = (byte) j;
trcLogger.data(TYPE_PUBLIC, className, "traceSample", data);
// Just before we leave a method, add an exit trace. It comes in two
// flavors: with and without a return code. We'll show both, but, just
// like entry tracing, you should only have one exit trace in a method.
// The first example also shows that, in static methods where the "this"
// object does not exist, you can use a string to name the class.
if (trcLogger.isLogging)
trcLogger.exit(TYPE_PUBLIC, "com.leh.eq.util.jLog.Sample", "traceSample");
if (trcLogger.isLogging)
trcLogger.exit(TYPE_PUBLIC, this, "traceSample", true);
}
/*----------------------------------------------------------------------
* Name: managerSample
*--------------------------------------------------------------------*/
/**
* Illustrates use of the {@link com.leh.eq.util.jLog.mgr.LogManager
LogManager}.
*/
public void managerSample()
{
PropertyDataStore ds = null;
// A Log Manager knows about log objects which have been configured in
// some persistent storage. We have to tell the Log Manager which
// storage we are using. We'll create one based on the sample properties
// file used to illustrate the format used by the PropertyDataStore
// class.
String propFile = "/com/ibm/logging/samples/DataStore.properties";
try
{
ds = new PropertyDataStore(propFile);
}
catch (LogIOException e)
{
System.err.println("Oooooo: " + e.getMessage());
}
// After creating the data store, a Log Manager is next. This method
//ensures
// that only one Log Manager exists.
LogManager mgr = LogManager.getManager(ds);
// Once you have a Log Manager, you can get loggers by name. If the
// configuration has been done properly, they should be ready to go,
// with handlers attached.
//
// Note that these loggers write to the console, not the Text Area used by
//the
// messageSample and traceSample methods.
MessageLogger ml1 = (MessageLogger) mgr.getMessageLogger("MessageLogger");
ml1.message(TYPE_WARN, className, "managerSample", "START_SERVER");
ml1.text(TYPE_WARN, className, "managerSample",
"This is a Log Manager demonstration. Insert 1 = {0}. Insert 2 = {1}.",
new Integer(88), "Parm X");
TraceLogger tl1 = (TraceLogger) mgr.getTraceLogger("TraceLogger");
tl1.isLogging = true;
if (tl1.isLogging)
tl1.exit(TYPE_PUBLIC, className, "managerSample", 999);
// The LogManager supports default message and trace loggers. If a named
//logger
// is requested, but no specific configuration for that logger exists, the
// LogManager will build it from the default configuration (if one exists).
// Here is an example. There is no configuration for a TestLogger in this
//sample.
MessageLogger ml2 = (MessageLogger) mgr.getMessageLogger("TestLogger");
ml2.text(TYPE_WARN, this, "managerSample",
"Demonstration of a logger built from the default configuration.");
// When you are done with the loggers, return them to the Log Manager.
mgr.returnObject(ml1);
mgr.returnObject(ml2);
mgr.returnObject(tl1);
}
}
//------------------------------------------- end of JLog.java------------------------------------------------------
(Review ID: 110321)
======================================================================
Name: tb29552 Date: 11/03/2000
java versiob "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
Source code :
import java.io.*;
import java.awt.*;
import java.awt.event.*;
class IntegerFieldListener implements ActionListener {
int value;
String name;
TextField txtfield;
MsgCanvas msg;
public void setField (TextField tf, Label lab, MsgCanvas m) {
name = lab.getText();
txtfield = tf;
msg = m;
}
public void actionPerformed(ActionEvent event) {
String str = event.getActionCommand();
System.out.println("Changed "+name+" "+str);
try {
value = Integer.parseInt(str);
System.out.println(name+" set to "+value);
}
catch (NumberFormatException e) {
if (txtfield != null) txtfield.setText("");
if (str == null) {
System.out.println("A value must be supplied for "+name);
msg.setText("A value must be supplied for "+name);
}
else {
System.out.println("Error parsing string "+str);
msg.setText("Error parsing string "+str);
}
}
}
}
Produces compiler output:
An exception has occurred in the compiler (1.3.0). Please file a bug at the Java
Developer Connection (http://java.sun.com/cgi-bin/bugreport.cgi). Include your
program and the following diagnostic in your report. Thank you.
java.lang.ArrayIndexOutOfBoundsException
at
com.sun.tools.javac.v8.code.ClassReader.readPool(ClassReader.java:390)
at
com.sun.tools.javac.v8.code.ClassReader.readName(ClassReader.java:491)
at
com.sun.tools.javac.v8.code.ClassReader.readClassAttrs(ClassReader.java:694)
at
com.sun.tools.javac.v8.code.ClassReader.readClass(ClassReader.java:787)
at
com.sun.tools.javac.v8.code.ClassReader.readClassFile(ClassReader.java:855)
at com.sun.tools.javac.v8.code.ClassReader.fillIn(ClassReader.java:984)
at
com.sun.tools.javac.v8.code.ClassReader.complete(ClassReader.java:952)
at com.sun.tools.javac.v8.code.Symbol.complete(Symbol.java:366)
at
com.sun.tools.javac.v8.code.ClassReader.loadClass(ClassReader.java:1012)
at com.sun.tools.javac.v8.comp.Resolve.loadClass(Resolve.java:460)
at com.sun.tools.javac.v8.comp.Resolve.findGlobalType(Resolve.java:528)
at com.sun.tools.javac.v8.comp.Resolve.findType(Resolve.java:579)
at com.sun.tools.javac.v8.comp.Resolve.findIdent(Resolve.java:610)
at com.sun.tools.javac.v8.comp.Resolve.resolveIdent(Resolve.java:771)
at com.sun.tools.javac.v8.comp.Attr._case(Attr.java:1044)
at com.sun.tools.javac.v8.tree.Tree$Ident.visit(Tree.java:983)
at com.sun.tools.javac.v8.comp.Attr.attribTree(Attr.java:234)
at com.sun.tools.javac.v8.comp.Attr.attribType(Attr.java:269)
at com.sun.tools.javac.v8.comp.Enter$MemberEnter._case(Enter.java:730)
at com.sun.tools.javac.v8.tree.Tree$VarDef.visit(Tree.java:470)
at
com.sun.tools.javac.v8.comp.Enter$MemberEnter.memberEnter(Enter.java:642)
at
com.sun.tools.javac.v8.comp.Enter$MemberEnter.memberEnter(Enter.java:658)
at
com.sun.tools.javac.v8.comp.Enter$CompleteEnter.finish(Enter.java:879)
at
com.sun.tools.javac.v8.comp.Enter$CompleteEnter.complete(Enter.java:865)
at com.sun.tools.javac.v8.code.Symbol.complete(Symbol.java:366)
at com.sun.tools.javac.v8.comp.Enter.main(Enter.java:544)
at com.sun.tools.javac.v8.JavaCompiler.compile(JavaCompiler.java:357)
at com.sun.tools.javac.v8.Main.compile(Main.java:247)
at com.sun.tools.javac.Main.main(Main.java:16)
Tool completed with exit code 4
Code compiles and executes properly on Solaris
java -version
java version "1.2.1"
Solaris VM (build Solaris_JDK_1.2.1_04c, native threads, sunwjit)
(Review ID: 111777)
======================================================================
Name: tb29552 Date: 10/03/2000
/*
An exception has occurred in the compiler. (v0.8)
Please file a bug report by sending your program and the following
diagnostic to
###@###.###.
Thank you.
java.lang.ArrayIndexOutOfBoundsException: -2063582768
at
com.sun.tools.javac.v8.code.ClassReader.nextInt(ClassReader.java:211)
at
com.sun.tools.javac.v8.code.ClassReader.skipMember(ClassReader.java:714)
at
com.sun.tools.javac.v8.code.ClassReader.readClass(ClassReader.java:756)
at
com.sun.tools.javac.v8.code.ClassReader.readClassFile(ClassReader.java:837)
at
com.sun.tools.javac.v8.code.ClassReader.fillIn(ClassReader.java:964)
at
com.sun.tools.javac.v8.code.ClassReader.complete(ClassReader.java:934)
at com.sun.tools.javac.v8.code.Symbol.complete(Symbol.java:263)
at
com.sun.tools.javac.v8.code.ClassReader.loadClass(ClassReader.java:986)
at com.sun.tools.javac.v8.comp.Resolve.loadClass(Resolve.java:500)
at
com.sun.tools.javac.v8.comp.Resolve.findGlobalType(Resolve.java:556)
at com.sun.tools.javac.v8.comp.Resolve.findType(Resolve.java:604)
at com.sun.tools.javac.v8.comp.Resolve.findIdent(Resolve.java:623)
at
com.sun.tools.javac.v8.comp.Resolve.resolveIdent(Resolve.java:780)
at com.sun.tools.javac.v8.comp.Attr._case(Attr.java:1289)
at com.sun.tools.javac.v8.tree.Tree$Ident.visit(Tree.java:815)
at com.sun.tools.javac.v8.comp.Attr.attribTree(Attr.java:250)
at com.sun.tools.javac.v8.comp.Attr.attribType(Attr.java:281)
at com.sun.tools.javac.v8.comp.Attr.attribBase(Attr.java:324)
at
com.sun.tools.javac.v8.comp.Enter$CompleteEnter.attribBase(Enter.java:999)
at
com.sun.tools.javac.v8.comp.Enter$CompleteEnter.complete(Enter.java:918)
at com.sun.tools.javac.v8.code.Symbol.complete(Symbol.java:263)
at com.sun.tools.javac.v8.comp.Enter.main(Enter.java:615)
at
com.sun.tools.javac.v8.JavaCompiler.compile(JavaCompiler.java:315)
at com.sun.tools.javac.v8.Main.compile(Main.java:247)
at com.sun.tools.javac.Main.main(Main.java:16)
----------------------------------------------------------------------------
---------------------------------------------
the java src code is
*/
//--------------------------------------------------------------------JLog.java-----------------------------------------
/**
* A Simple client interface to the IBM JLog package
*
*/
//package com.leh.eq.util;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import com.ibm.logging.*;
import com.ibm.logging.mgr.*;
/**
* This sample program demonstrates how one might use the Logging Toolkit
* to log messages and trace the flow of a program.
**/
// If your program implements IRecordType, you do not have to preface
// every use of the TYPE_XXX constants with the interface name.
public class JLog implements IRecordType
{
private static final String S = "TEST"; // ICopyright.COPYRIGHT_98_99;
// Indicate whether we are running as an applet or an application.
private transient boolean isApplet = false;
// Name the file containing our message texts.
private static final String MSG_FILE = "com.leh.eq.util.jLog.samples.Msgs";
// Define the name of this class for the logging methods.
private String className;
// Define a few logging objects that are needed in this sample application.
// They could certainly be initialized here, but we will do it in
// init(), just to keep it all in one place. These objects are
// global in scope because this is a small application. In a larger
// program, you may want to create more loggers with limited scope to
// selectively control logging in different parts of the program.
//
// To start, we need at least one message logger and one trace logger.
// We'll create several different handlers to demonstrate how they
// can be connected. See the init method for more on this.
private transient MessageLogger msgLogger;
private transient TraceLogger trcLogger;
private transient FileHandler msgLog;
private transient FileHandler trcLog;
/*----------------------------------------------------------------------
* Name: main
*--------------------------------------------------------------------*/
/**
* Main entry point for the <code>Sample</code> application.
* This sample takes no arguments.
*/
public static void main(String args[])
{
// Create a Sample object and start it.
JLog sample = new JLog();
sample.isApplet = false;
sample.init();
sample.runSample();
// sample.destroy();
}
/*----------------------------------------------------------------------
* Name: Sample
*--------------------------------------------------------------------*/
/**
* Creates a <code>JLog</code>.
*/
public JLog()
{
}
/*----------------------------------------------------------------------
* Name: init
*--------------------------------------------------------------------*/
/**
* Initializes the logging system.
*/
public void init()
{
// Get the name of this class.
className = this.getClass().getName();
// To log messages, we must create at least one MessageLogger. We
// recommend always giving loggers a name and a description.
msgLogger = new MessageLogger("MsgLogger", "Sample Message Logger");
// To trace program execution, we need at least one TraceLogger. Like the
// MessageLogger, we will give this one a name and a description.
trcLogger = new TraceLogger("TrcLogger", "Sample Trace Logger");
// Without at least one Handler, the message and trace data is lost.
// In this sample, we will create several different handlers: one
// to send data to the console and two to log to separate files. The
// console will receive message and trace data. One file will receive
// messages and the other, trace data. The point is that, if you want,
// you can send the same data to different devices. Perhaps you want error
// messages displayed on a console, and all messages logged to a file.
// The Logging Toolkit code is provided in signed JAR and CAB files for the
//Netscape
// and Internet Explorer browsers. This is required for Netscape, as their
// implementation of getResourceAsStream will not read the log message
// (properties) file unless it is in a JAR file.
//
// Even though the JAR is signed, the Logging Toolkit contains no browser
//security
// requests. This prevents people from doing Really Bad Things in their
// application and causing the browser to pop a window that says that IBM is
// requesting privileges to do things that the normal security of a browser
// will not allow. If you need to do things like write to the local file
// system or make a sockets connection to a machine other than your web
//server,
// you must place the proper browser security requests in your own
//application
// and sign its JAR/CAB files.
//
// In this application, there are several places where things are done
//differently
// depending on whether the program is running as an application or an
//applet.
// This is merely because this sample runs in an unsigned JAR or CAB and the
// browser won't let it do some things. Here's the first. An applet can't
//write
// to the local file system.
msgLog = new FileHandler("MsgLog", "Message Log", "Message.log");
trcLog = new FileHandler("TrcLog", "Trace Log");
trcLog.setFileName("Trace.log");
// The basic MessageLogger configuration is complete when you attach
// to it at least one Handler. Ours get two handlers.
msgLogger.addHandler(msgLog);
// The text for log messages is usually kept in a resource bundle and the
// message text is accessed by a "key," which is, essentially, a name for
// the text. If you have only one bundles containing your message text
// it is probably easier to pass its name to the message logger and
// use the message() methods that don't include a message file name.
// We'll do just that.
msgLogger.setMessageFile(MSG_FILE);
// There are a few fields in a message that tend not to vary from record
// to record. If we want them included in the formatted message, we have
// to tell the MessageLogger. Let's include them all. In practice,
// an application might not have a server associated with it -- but an
// applet would. We'll just make up a server name. We'll get our
// IP name and use that as our client name.
msgLogger.setOrganization("LehEQEComm");
msgLogger.setProduct("JLog");
msgLogger.setComponent("Tester ");
msgLogger.setServer("logger.ibm.com");
String client = "localhost";
// Here's another restriction. Applets can't get their host name.
try
{
client = InetAddress.getLocalHost().getHostName();
}
catch (UnknownHostException uE)
{
}
msgLogger.setClient(client);
// For the trace logger, we just add the desired handlers.
// Note that the message logger and the trace logger share the
// console handler, but their data is going to separate files.
trcLogger.addHandler(trcLog);
// The default filter in the handlers logs all messages. Let's change
// this so that only warning and error messages go to the console.
// We'll leave the message log alone, so that it receives all messages.
//
// Note that it is possible to set a filter in the loggers, too.
// In practice, you will probably pick one place or the other, not both.
// If you set different filters in different loggers, you can control the
// kind of data logged in different parts of your program. If you set the
// filters in the handlers, you control what goes to each output device.
// Message logging is enabled when the MessageLogger is created.
// Trace logging is off. Let's turn it on.
trcLogger.isLogging = true;
}
/*----------------------------------------------------------------------
* Name: destroy
*--------------------------------------------------------------------*/
public void destroy()
{
// Before we terminate, stop the handlers, which are running on
// their own threads.
msgLog.stop();
trcLog.stop();
}
/*----------------------------------------------------------------------
* Name: runSample()
*--------------------------------------------------------------------*/
/**
* Runs the sample, which demonstrates programming using the Logging
* Toolkit.
*/
public void runSample()
{
// Illustrate message logging.
messageSample();
// Illustrate trace logging.
traceSample();
// Demonstrate how a Log Manager is used.
managerSample();
}
/*----------------------------------------------------------------------
* Name: messageSample
*--------------------------------------------------------------------*/
/**
* Illustrates message logging.
*/
public void messageSample()
{
// Here are some samples of message logging. In this example, a
// static message (no run-time information) is logged. It is an
// informational message. This message will not be written to the
// console, since its message mask only includes warning and error
// messages.
msgLogger.message(TYPE_INFO, this, "messageSample", "START_SERVER");
// Here is a message that shows how to insert run-time information
// into a message. This is similar to the C-language printf function,
// which accepts an arbitrary number of values to be plugged into a
// message. We'll insert the day and a temperature into this message.
// In Msgs.java, you will see that "day" is represented by "{0}" and
// "temp" by "{1}". Substitution of variables into the text depends on
// the order in which the variables are passed to the message method.
SimpleDateFormat sf = new SimpleDateFormat("EEEEE");
Date date = new Date();
String day = sf.format(date);
Integer temp = new Integer(91);
msgLogger.message(TYPE_WARN, className, "messageSample", "HOT_DAY", day,
temp);
// If you have more than two objects to insert in a message, you have to
// build an Object array. We'll just use the same string and two objects.
// If you like arrays, you can always use this approach!
Object[] inserts = new Object[2];
inserts[0] = day;
inserts[1] = new Integer(101); // It's really hot now!
msgLogger.message(TYPE_WARN, className, "messageSample", "HOT_DAY",
inserts);
// If your message is being logged in a static method, there is
// no "this" object from which the class name can be derived. You have
// to name the class. You can use this approach even in a non-static
// method, if you are so inclined.
msgLogger.message(TYPE_ERR, "com.leh.eq.util.jLog.Sample", "messageSample",
"STATIC");
// These message logging examples work because the message file to use
// was specified using the setMessageFile() method. We can, instead, name
// the message file on every message() call. We'll remove the message file
// to demonstrate that this approach works as well. (Note that the msg()
// methods, not message(), are used when you want to specify the key and the
// message file.)
//
// You have to name the message file if you have more than one, though you
// could call MessageLogger.setMessageFile for the most commonly used
// message file and use the msg methods only when needed.
msgLogger.setMessageFile("");
msgLogger.msg(TYPE_ERR, this, "messageSample",
"STATIC", MSG_FILE);
msgLogger.setMessageFile(MSG_FILE);
// Message logging is intended to be done through message keys and
// resource bundles so that the messages can be translated. However,
// some support is available for logging non-translatable text messages.
// These methods accept additional Objects, which are displayed through
// their toString methods. These objects are inserted into the message
// text using the MessageFormat class, as is done with the message and
// msg methods.
msgLogger.text(TYPE_WARN, className, "messageSample",
"This method has no additional parameters.");
msgLogger.text(TYPE_WARN, this, "messageSample",
"This method adds two additional parameters: {0}, {1}",
new Integer(51), "Parm 2");
// Exceptions can also be traced.
msgLogger.exception(TYPE_ERR, className, "messageSample",
new Exception("Exception demo."));
// Handlers may also operate in a circular mode, buffering log records
// until they are told to dump the queue. In this example, the records
// whose message texts are "Circular test 0" and "Circular test 1" will be
// lost when the buffer wraps.
ConsoleHandler ch = new ConsoleHandler();
ch.setQueueCapacity(7);
ch.setCircular(true);
msgLogger.addHandler(ch);
for (int i = 0; i < 9; i++)
msgLogger.text(TYPE_WARN, className, "messageSample",
"Circular test " + i);
ch.dumpQueue();
ch.stop();
// After a handler is stopped, it can be restarted with a subsequent call
// to start().
ch.setCircular(false);
ch.start();
for (int i = 20; i < 25; i++)
msgLogger.text(TYPE_WARN, className, "messageSample",
"Circular test " + i);
ch.stop();
}
/*--------------------------------------------------------------------
* Name: traceSample
*--------------------------------------------------------------------*/
/**
* Illustrates trace logging.
*/
public void traceSample()
{
// Entry/exit tracing is useful to see the methods that are executing.
// Knowing that something bad happened in a program is often not useful --
// unless you know how you got there!
//
// Note that the entry method is wrapped in a test of the public boolean
// "isLogging." This quick test avoids the overhead of the method call
// if tracing is off. We've given this entry a type of "public" -- a
// general public method. The entry method will add TYPE_ENTRY to
// this as a convenience to the programmer. This example shows
// that the entry method can accept additional parameters to be
// traced. These should be the parameters passed into the method
// whose entry you are tracing.
int i = 5;
String s = "This is a test";
if (trcLogger.isLogging)
trcLogger.entry(TYPE_PUBLIC, className, "traceSample",
s, new Integer(i));
// We would normally only have only one entry call in a method.
// To illustrate a few points, this methods gets more than one!
//
// This example also shows an entry trace with no parameters. If
// you have more than two parameters, you have to create an Object[],
// just as was shown for message tracing.
if (trcLogger.isLogging)
trcLogger.entry(TYPE_PUBLIC, this, "traceSample");
// Here's an example of creating an Object array of four parameters.
Object[] parms = {"a", "b", "c", "d"};
if (trcLogger.isLogging)
trcLogger.entry(TYPE_PUBLIC, className, "traceSample", parms);
// For general tracing, use the text method. You can trace any String
// that you care to build. This sample illustrates the use of trace types.
if (trcLogger.isLogging)
{
String msg = "1. Trace is valuable when Baddd Things happen to Good Code.";
trcLogger.text(TYPE_SVC, className, "traceSample", msg);
}
// Exceptions can also be traced. Note that you can test the isLogging()
// method as well as the isLogging boolean.
if (trcLogger.isLogging())
trcLogger.exception(TYPE_ERROR_EXC, this, "traceSample", new
Exception("Testing exception"));
// Here's one using a NestedException. This allows you to add your own
// message to that contained in the exception. We'll show it in a try/catch
// block, just as if you caught an exception and wished to log the error.
try
{
throw new LogException("A message in a LogException");
}
catch (LogException e)
{
NestedException ne = new NestedException("An additional message in a NestedException", e);
if (trcLogger.isLogging())
trcLogger.exception(TYPE_ERROR_EXC, className, "traceSample", ne);
// Let's do it again, but use a localized message.
MessageCatalog cat = new
MessageCatalog("com.leh.eq.util.jLog.samples.Msgs");
ne = new NestedException(cat.getMessage("STATIC"), e);
if (trcLogger.isLogging())
trcLogger.exception(TYPE_ERROR_EXC, this, "traceSample", ne);
}
// If you'd need to see the call stack, use the stackTrace method.
if (trcLogger.isLogging)
trcLogger.stackTrace(TYPE_PUBLIC, className, "traceSample");
// Here is an example of tracing an array of bytes.
byte[] data = new byte[69];
for (int j = 0; j < 69; j++)
data[j] = (byte) j;
trcLogger.data(TYPE_PUBLIC, className, "traceSample", data);
// Just before we leave a method, add an exit trace. It comes in two
// flavors: with and without a return code. We'll show both, but, just
// like entry tracing, you should only have one exit trace in a method.
// The first example also shows that, in static methods where the "this"
// object does not exist, you can use a string to name the class.
if (trcLogger.isLogging)
trcLogger.exit(TYPE_PUBLIC, "com.leh.eq.util.jLog.Sample", "traceSample");
if (trcLogger.isLogging)
trcLogger.exit(TYPE_PUBLIC, this, "traceSample", true);
}
/*----------------------------------------------------------------------
* Name: managerSample
*--------------------------------------------------------------------*/
/**
* Illustrates use of the {@link com.leh.eq.util.jLog.mgr.LogManager
LogManager}.
*/
public void managerSample()
{
PropertyDataStore ds = null;
// A Log Manager knows about log objects which have been configured in
// some persistent storage. We have to tell the Log Manager which
// storage we are using. We'll create one based on the sample properties
// file used to illustrate the format used by the PropertyDataStore
// class.
String propFile = "/com/ibm/logging/samples/DataStore.properties";
try
{
ds = new PropertyDataStore(propFile);
}
catch (LogIOException e)
{
System.err.println("Oooooo: " + e.getMessage());
}
// After creating the data store, a Log Manager is next. This method
//ensures
// that only one Log Manager exists.
LogManager mgr = LogManager.getManager(ds);
// Once you have a Log Manager, you can get loggers by name. If the
// configuration has been done properly, they should be ready to go,
// with handlers attached.
//
// Note that these loggers write to the console, not the Text Area used by
//the
// messageSample and traceSample methods.
MessageLogger ml1 = (MessageLogger) mgr.getMessageLogger("MessageLogger");
ml1.message(TYPE_WARN, className, "managerSample", "START_SERVER");
ml1.text(TYPE_WARN, className, "managerSample",
"This is a Log Manager demonstration. Insert 1 = {0}. Insert 2 = {1}.",
new Integer(88), "Parm X");
TraceLogger tl1 = (TraceLogger) mgr.getTraceLogger("TraceLogger");
tl1.isLogging = true;
if (tl1.isLogging)
tl1.exit(TYPE_PUBLIC, className, "managerSample", 999);
// The LogManager supports default message and trace loggers. If a named
//logger
// is requested, but no specific configuration for that logger exists, the
// LogManager will build it from the default configuration (if one exists).
// Here is an example. There is no configuration for a TestLogger in this
//sample.
MessageLogger ml2 = (MessageLogger) mgr.getMessageLogger("TestLogger");
ml2.text(TYPE_WARN, this, "managerSample",
"Demonstration of a logger built from the default configuration.");
// When you are done with the loggers, return them to the Log Manager.
mgr.returnObject(ml1);
mgr.returnObject(ml2);
mgr.returnObject(tl1);
}
}
//------------------------------------------- end of JLog.java------------------------------------------------------
(Review ID: 110321)
======================================================================
Name: tb29552 Date: 11/03/2000
java versiob "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
Source code :
import java.io.*;
import java.awt.*;
import java.awt.event.*;
class IntegerFieldListener implements ActionListener {
int value;
String name;
TextField txtfield;
MsgCanvas msg;
public void setField (TextField tf, Label lab, MsgCanvas m) {
name = lab.getText();
txtfield = tf;
msg = m;
}
public void actionPerformed(ActionEvent event) {
String str = event.getActionCommand();
System.out.println("Changed "+name+" "+str);
try {
value = Integer.parseInt(str);
System.out.println(name+" set to "+value);
}
catch (NumberFormatException e) {
if (txtfield != null) txtfield.setText("");
if (str == null) {
System.out.println("A value must be supplied for "+name);
msg.setText("A value must be supplied for "+name);
}
else {
System.out.println("Error parsing string "+str);
msg.setText("Error parsing string "+str);
}
}
}
}
Produces compiler output:
An exception has occurred in the compiler (1.3.0). Please file a bug at the Java
Developer Connection (http://java.sun.com/cgi-bin/bugreport.cgi). Include your
program and the following diagnostic in your report. Thank you.
java.lang.ArrayIndexOutOfBoundsException
at
com.sun.tools.javac.v8.code.ClassReader.readPool(ClassReader.java:390)
at
com.sun.tools.javac.v8.code.ClassReader.readName(ClassReader.java:491)
at
com.sun.tools.javac.v8.code.ClassReader.readClassAttrs(ClassReader.java:694)
at
com.sun.tools.javac.v8.code.ClassReader.readClass(ClassReader.java:787)
at
com.sun.tools.javac.v8.code.ClassReader.readClassFile(ClassReader.java:855)
at com.sun.tools.javac.v8.code.ClassReader.fillIn(ClassReader.java:984)
at
com.sun.tools.javac.v8.code.ClassReader.complete(ClassReader.java:952)
at com.sun.tools.javac.v8.code.Symbol.complete(Symbol.java:366)
at
com.sun.tools.javac.v8.code.ClassReader.loadClass(ClassReader.java:1012)
at com.sun.tools.javac.v8.comp.Resolve.loadClass(Resolve.java:460)
at com.sun.tools.javac.v8.comp.Resolve.findGlobalType(Resolve.java:528)
at com.sun.tools.javac.v8.comp.Resolve.findType(Resolve.java:579)
at com.sun.tools.javac.v8.comp.Resolve.findIdent(Resolve.java:610)
at com.sun.tools.javac.v8.comp.Resolve.resolveIdent(Resolve.java:771)
at com.sun.tools.javac.v8.comp.Attr._case(Attr.java:1044)
at com.sun.tools.javac.v8.tree.Tree$Ident.visit(Tree.java:983)
at com.sun.tools.javac.v8.comp.Attr.attribTree(Attr.java:234)
at com.sun.tools.javac.v8.comp.Attr.attribType(Attr.java:269)
at com.sun.tools.javac.v8.comp.Enter$MemberEnter._case(Enter.java:730)
at com.sun.tools.javac.v8.tree.Tree$VarDef.visit(Tree.java:470)
at
com.sun.tools.javac.v8.comp.Enter$MemberEnter.memberEnter(Enter.java:642)
at
com.sun.tools.javac.v8.comp.Enter$MemberEnter.memberEnter(Enter.java:658)
at
com.sun.tools.javac.v8.comp.Enter$CompleteEnter.finish(Enter.java:879)
at
com.sun.tools.javac.v8.comp.Enter$CompleteEnter.complete(Enter.java:865)
at com.sun.tools.javac.v8.code.Symbol.complete(Symbol.java:366)
at com.sun.tools.javac.v8.comp.Enter.main(Enter.java:544)
at com.sun.tools.javac.v8.JavaCompiler.compile(JavaCompiler.java:357)
at com.sun.tools.javac.v8.Main.compile(Main.java:247)
at com.sun.tools.javac.Main.main(Main.java:16)
Tool completed with exit code 4
Code compiles and executes properly on Solaris
java -version
java version "1.2.1"
Solaris VM (build Solaris_JDK_1.2.1_04c, native threads, sunwjit)
(Review ID: 111777)
======================================================================
Name: tb29552 Date: 10/03/2000
/*
An exception has occurred in the compiler. (v0.8)
Please file a bug report by sending your program and the following
diagnostic to
###@###.###.
Thank you.
java.lang.ArrayIndexOutOfBoundsException: -2063582768
at
com.sun.tools.javac.v8.code.ClassReader.nextInt(ClassReader.java:211)
at
com.sun.tools.javac.v8.code.ClassReader.skipMember(ClassReader.java:714)
at
com.sun.tools.javac.v8.code.ClassReader.readClass(ClassReader.java:756)
at
com.sun.tools.javac.v8.code.ClassReader.readClassFile(ClassReader.java:837)
at
com.sun.tools.javac.v8.code.ClassReader.fillIn(ClassReader.java:964)
at
com.sun.tools.javac.v8.code.ClassReader.complete(ClassReader.java:934)
at com.sun.tools.javac.v8.code.Symbol.complete(Symbol.java:263)
at
com.sun.tools.javac.v8.code.ClassReader.loadClass(ClassReader.java:986)
at com.sun.tools.javac.v8.comp.Resolve.loadClass(Resolve.java:500)
at
com.sun.tools.javac.v8.comp.Resolve.findGlobalType(Resolve.java:556)
at com.sun.tools.javac.v8.comp.Resolve.findType(Resolve.java:604)
at com.sun.tools.javac.v8.comp.Resolve.findIdent(Resolve.java:623)
at
com.sun.tools.javac.v8.comp.Resolve.resolveIdent(Resolve.java:780)
at com.sun.tools.javac.v8.comp.Attr._case(Attr.java:1289)
at com.sun.tools.javac.v8.tree.Tree$Ident.visit(Tree.java:815)
at com.sun.tools.javac.v8.comp.Attr.attribTree(Attr.java:250)
at com.sun.tools.javac.v8.comp.Attr.attribType(Attr.java:281)
at com.sun.tools.javac.v8.comp.Attr.attribBase(Attr.java:324)
at
com.sun.tools.javac.v8.comp.Enter$CompleteEnter.attribBase(Enter.java:999)
at
com.sun.tools.javac.v8.comp.Enter$CompleteEnter.complete(Enter.java:918)
at com.sun.tools.javac.v8.code.Symbol.complete(Symbol.java:263)
at com.sun.tools.javac.v8.comp.Enter.main(Enter.java:615)
at
com.sun.tools.javac.v8.JavaCompiler.compile(JavaCompiler.java:315)
at com.sun.tools.javac.v8.Main.compile(Main.java:247)
at com.sun.tools.javac.Main.main(Main.java:16)
----------------------------------------------------------------------------
---------------------------------------------
the java src code is
*/
//--------------------------------------------------------------------JLog.java-----------------------------------------
/**
* A Simple client interface to the IBM JLog package
*
*/
//package com.leh.eq.util;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import com.ibm.logging.*;
import com.ibm.logging.mgr.*;
/**
* This sample program demonstrates how one might use the Logging Toolkit
* to log messages and trace the flow of a program.
**/
// If your program implements IRecordType, you do not have to preface
// every use of the TYPE_XXX constants with the interface name.
public class JLog implements IRecordType
{
private static final String S = "TEST"; // ICopyright.COPYRIGHT_98_99;
// Indicate whether we are running as an applet or an application.
private transient boolean isApplet = false;
// Name the file containing our message texts.
private static final String MSG_FILE = "com.leh.eq.util.jLog.samples.Msgs";
// Define the name of this class for the logging methods.
private String className;
// Define a few logging objects that are needed in this sample application.
// They could certainly be initialized here, but we will do it in
// init(), just to keep it all in one place. These objects are
// global in scope because this is a small application. In a larger
// program, you may want to create more loggers with limited scope to
// selectively control logging in different parts of the program.
//
// To start, we need at least one message logger and one trace logger.
// We'll create several different handlers to demonstrate how they
// can be connected. See the init method for more on this.
private transient MessageLogger msgLogger;
private transient TraceLogger trcLogger;
private transient FileHandler msgLog;
private transient FileHandler trcLog;
/*----------------------------------------------------------------------
* Name: main
*--------------------------------------------------------------------*/
/**
* Main entry point for the <code>Sample</code> application.
* This sample takes no arguments.
*/
public static void main(String args[])
{
// Create a Sample object and start it.
JLog sample = new JLog();
sample.isApplet = false;
sample.init();
sample.runSample();
// sample.destroy();
}
/*----------------------------------------------------------------------
* Name: Sample
*--------------------------------------------------------------------*/
/**
* Creates a <code>JLog</code>.
*/
public JLog()
{
}
/*----------------------------------------------------------------------
* Name: init
*--------------------------------------------------------------------*/
/**
* Initializes the logging system.
*/
public void init()
{
// Get the name of this class.
className = this.getClass().getName();
// To log messages, we must create at least one MessageLogger. We
// recommend always giving loggers a name and a description.
msgLogger = new MessageLogger("MsgLogger", "Sample Message Logger");
// To trace program execution, we need at least one TraceLogger. Like the
// MessageLogger, we will give this one a name and a description.
trcLogger = new TraceLogger("TrcLogger", "Sample Trace Logger");
// Without at least one Handler, the message and trace data is lost.
// In this sample, we will create several different handlers: one
// to send data to the console and two to log to separate files. The
// console will receive message and trace data. One file will receive
// messages and the other, trace data. The point is that, if you want,
// you can send the same data to different devices. Perhaps you want error
// messages displayed on a console, and all messages logged to a file.
// The Logging Toolkit code is provided in signed JAR and CAB files for the
//Netscape
// and Internet Explorer browsers. This is required for Netscape, as their
// implementation of getResourceAsStream will not read the log message
// (properties) file unless it is in a JAR file.
//
// Even though the JAR is signed, the Logging Toolkit contains no browser
//security
// requests. This prevents people from doing Really Bad Things in their
// application and causing the browser to pop a window that says that IBM is
// requesting privileges to do things that the normal security of a browser
// will not allow. If you need to do things like write to the local file
// system or make a sockets connection to a machine other than your web
//server,
// you must place the proper browser security requests in your own
//application
// and sign its JAR/CAB files.
//
// In this application, there are several places where things are done
//differently
// depending on whether the program is running as an application or an
//applet.
// This is merely because this sample runs in an unsigned JAR or CAB and the
// browser won't let it do some things. Here's the first. An applet can't
//write
// to the local file system.
msgLog = new FileHandler("MsgLog", "Message Log", "Message.log");
trcLog = new FileHandler("TrcLog", "Trace Log");
trcLog.setFileName("Trace.log");
// The basic MessageLogger configuration is complete when you attach
// to it at least one Handler. Ours get two handlers.
msgLogger.addHandler(msgLog);
// The text for log messages is usually kept in a resource bundle and the
// message text is accessed by a "key," which is, essentially, a name for
// the text. If you have only one bundles containing your message text
// it is probably easier to pass its name to the message logger and
// use the message() methods that don't include a message file name.
// We'll do just that.
msgLogger.setMessageFile(MSG_FILE);
// There are a few fields in a message that tend not to vary from record
// to record. If we want them included in the formatted message, we have
// to tell the MessageLogger. Let's include them all. In practice,
// an application might not have a server associated with it -- but an
// applet would. We'll just make up a server name. We'll get our
// IP name and use that as our client name.
msgLogger.setOrganization("LehEQEComm");
msgLogger.setProduct("JLog");
msgLogger.setComponent("Tester ");
msgLogger.setServer("logger.ibm.com");
String client = "localhost";
// Here's another restriction. Applets can't get their host name.
try
{
client = InetAddress.getLocalHost().getHostName();
}
catch (UnknownHostException uE)
{
}
msgLogger.setClient(client);
// For the trace logger, we just add the desired handlers.
// Note that the message logger and the trace logger share the
// console handler, but their data is going to separate files.
trcLogger.addHandler(trcLog);
// The default filter in the handlers logs all messages. Let's change
// this so that only warning and error messages go to the console.
// We'll leave the message log alone, so that it receives all messages.
//
// Note that it is possible to set a filter in the loggers, too.
// In practice, you will probably pick one place or the other, not both.
// If you set different filters in different loggers, you can control the
// kind of data logged in different parts of your program. If you set the
// filters in the handlers, you control what goes to each output device.
// Message logging is enabled when the MessageLogger is created.
// Trace logging is off. Let's turn it on.
trcLogger.isLogging = true;
}
/*----------------------------------------------------------------------
* Name: destroy
*--------------------------------------------------------------------*/
public void destroy()
{
// Before we terminate, stop the handlers, which are running on
// their own threads.
msgLog.stop();
trcLog.stop();
}
/*----------------------------------------------------------------------
* Name: runSample()
*--------------------------------------------------------------------*/
/**
* Runs the sample, which demonstrates programming using the Logging
* Toolkit.
*/
public void runSample()
{
// Illustrate message logging.
messageSample();
// Illustrate trace logging.
traceSample();
// Demonstrate how a Log Manager is used.
managerSample();
}
/*----------------------------------------------------------------------
* Name: messageSample
*--------------------------------------------------------------------*/
/**
* Illustrates message logging.
*/
public void messageSample()
{
// Here are some samples of message logging. In this example, a
// static message (no run-time information) is logged. It is an
// informational message. This message will not be written to the
// console, since its message mask only includes warning and error
// messages.
msgLogger.message(TYPE_INFO, this, "messageSample", "START_SERVER");
// Here is a message that shows how to insert run-time information
// into a message. This is similar to the C-language printf function,
// which accepts an arbitrary number of values to be plugged into a
// message. We'll insert the day and a temperature into this message.
// In Msgs.java, you will see that "day" is represented by "{0}" and
// "temp" by "{1}". Substitution of variables into the text depends on
// the order in which the variables are passed to the message method.
SimpleDateFormat sf = new SimpleDateFormat("EEEEE");
Date date = new Date();
String day = sf.format(date);
Integer temp = new Integer(91);
msgLogger.message(TYPE_WARN, className, "messageSample", "HOT_DAY", day,
temp);
// If you have more than two objects to insert in a message, you have to
// build an Object array. We'll just use the same string and two objects.
// If you like arrays, you can always use this approach!
Object[] inserts = new Object[2];
inserts[0] = day;
inserts[1] = new Integer(101); // It's really hot now!
msgLogger.message(TYPE_WARN, className, "messageSample", "HOT_DAY",
inserts);
// If your message is being logged in a static method, there is
// no "this" object from which the class name can be derived. You have
// to name the class. You can use this approach even in a non-static
// method, if you are so inclined.
msgLogger.message(TYPE_ERR, "com.leh.eq.util.jLog.Sample", "messageSample",
"STATIC");
// These message logging examples work because the message file to use
// was specified using the setMessageFile() method. We can, instead, name
// the message file on every message() call. We'll remove the message file
// to demonstrate that this approach works as well. (Note that the msg()
// methods, not message(), are used when you want to specify the key and the
// message file.)
//
// You have to name the message file if you have more than one, though you
// could call MessageLogger.setMessageFile for the most commonly used
// message file and use the msg methods only when needed.
msgLogger.setMessageFile("");
msgLogger.msg(TYPE_ERR, this, "messageSample",
"STATIC", MSG_FILE);
msgLogger.setMessageFile(MSG_FILE);
// Message logging is intended to be done through message keys and
// resource bundles so that the messages can be translated. However,
// some support is available for logging non-translatable text messages.
// These methods accept additional Objects, which are displayed through
// their toString methods. These objects are inserted into the message
// text using the MessageFormat class, as is done with the message and
// msg methods.
msgLogger.text(TYPE_WARN, className, "messageSample",
"This method has no additional parameters.");
msgLogger.text(TYPE_WARN, this, "messageSample",
"This method adds two additional parameters: {0}, {1}",
new Integer(51), "Parm 2");
// Exceptions can also be traced.
msgLogger.exception(TYPE_ERR, className, "messageSample",
new Exception("Exception demo."));
// Handlers may also operate in a circular mode, buffering log records
// until they are told to dump the queue. In this example, the records
// whose message texts are "Circular test 0" and "Circular test 1" will be
// lost when the buffer wraps.
ConsoleHandler ch = new ConsoleHandler();
ch.setQueueCapacity(7);
ch.setCircular(true);
msgLogger.addHandler(ch);
for (int i = 0; i < 9; i++)
msgLogger.text(TYPE_WARN, className, "messageSample",
"Circular test " + i);
ch.dumpQueue();
ch.stop();
// After a handler is stopped, it can be restarted with a subsequent call
// to start().
ch.setCircular(false);
ch.start();
for (int i = 20; i < 25; i++)
msgLogger.text(TYPE_WARN, className, "messageSample",
"Circular test " + i);
ch.stop();
}
/*--------------------------------------------------------------------
- relates to
-
JDK-6232676 javac crashes with ArrayIndexOutOfBoundsException on ZIP merged jar files.
- Closed