This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 190079
Collapse All | Expand All

(-)a/openide.util/apichanges.xml (+17 lines)
Lines 51-56 Link Here
51
    <apidef name="actions">Actions API</apidef>
51
    <apidef name="actions">Actions API</apidef>
52
</apidefs>
52
</apidefs>
53
<changes>
53
<changes>
54
    <change id="Exceptions.attachSeverity">
55
        <api name="util"/>
56
        <summary>Supress logging of not important exceptions</summary>
57
        <version major="8" minor="8"/>
58
        <date day="8" month="9" year="2010"/>
59
        <author login="jtulach"/>
60
        <compatibility addition="yes"/>
61
        <description>
62
            <p>
63
                New method <code>Exceptions.attachSeverity</code> allows 
64
                everyone to thrown an exception, which later will not be 
65
                logged.
66
            </p>
67
        </description>
68
        <class package="org.openide.util" name="Exceptions"/>
69
        <issue number="190079"/>
70
    </change>
54
    <change id="RequestProcessorForClass">
71
    <change id="RequestProcessorForClass">
55
        <api name="util"/>
72
        <api name="util"/>
56
        <summary>Simplified constructor for RequestProcessor</summary>
73
        <summary>Simplified constructor for RequestProcessor</summary>
(-)a/openide.util/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.util
2
OpenIDE-Module: org.openide.util
3
OpenIDE-Module-Localizing-Bundle: org/openide/util/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/util/Bundle.properties
4
OpenIDE-Module-Specification-Version: 8.7
4
OpenIDE-Module-Specification-Version: 8.8
5
5
(-)a/openide.util/src/org/openide/util/Exceptions.java (-1 / +34 lines)
Lines 115-120 Link Here
115
        ae.addRecord(rec);
115
        ae.addRecord(rec);
116
        return e;
116
        return e;
117
    }
117
    }
118
    
119
    /**
120
     * Attaches a given severity to the exception. When the exception is
121
     * later passed to {@link #printStackTrace} method, the level is
122
     * then used as a level for reported {@link LogRecord}. This allows
123
     * those who report exceptions to annotate them as unimportant,
124
     * expected.
125
     * 
126
     * @param e exception to assign severity to
127
     * @param severity the severity
128
     * @since 8.8
129
     */
130
    public static <E extends Throwable> E attachSeverity(E e, Level severity) {
131
        AnnException ae = AnnException.findOrCreate(e, true);
132
        ae.addRecord(new LogRecord(severity, null));
133
        return e;
134
    }
118
135
119
    /** Extracts previously attached localized message for a given throwable.
136
    /** Extracts previously attached localized message for a given throwable.
120
     * Complements {@link #attachLocalizedMessage}.
137
     * Complements {@link #attachLocalizedMessage}.
Lines 171-182 Link Here
171
     * @param t the exception to notify
188
     * @param t the exception to notify
172
     */
189
     */
173
    public static void printStackTrace(Throwable t) {
190
    public static void printStackTrace(Throwable t) {
191
        AnnException ae = AnnException.findOrCreate(t, false);
192
        Level level = null;
193
        if (ae != null) {
194
            for (LogRecord r : ae.records) {
195
                if (r.getLevel() != Level.ALL) {
196
                    level = r.getLevel();
197
                    break;
198
                }
199
            }
200
        }
201
        if (level == null) {
202
            level = OwnLevel.UNKNOWN;
203
        }
174
        AnnException extra = AnnException.extras.get(t);
204
        AnnException extra = AnnException.extras.get(t);
175
        if (extra != null) {
205
        if (extra != null) {
176
            assert t == extra.getCause();
206
            assert t == extra.getCause();
177
            t = extra;
207
            t = extra;
178
        }
208
        }
179
        LOG.log(OwnLevel.UNKNOWN, null, t);
209
        LOG.log(level, null, t);
180
    }
210
    }
181
211
182
    /** An exception that has a log record associated with itself, so
212
    /** An exception that has a log record associated with itself, so
Lines 213-218 Link Here
213
        private static Map<Throwable, AnnException> extras = new WeakHashMap<Throwable, AnnException>();
243
        private static Map<Throwable, AnnException> extras = new WeakHashMap<Throwable, AnnException>();
214
244
215
        static AnnException findOrCreate(Throwable t, boolean create) {
245
        static AnnException findOrCreate(Throwable t, boolean create) {
246
            if (t == null) {
247
                return null;
248
            }
216
            if (t instanceof AnnException) {
249
            if (t instanceof AnnException) {
217
                return (AnnException)t;
250
                return (AnnException)t;
218
            }
251
            }
(-)a/openide.util/test/unit/src/org/openide/util/ExceptionsTest.java (+40 lines)
Lines 44-52 Link Here
44
44
45
package org.openide.util;
45
package org.openide.util;
46
46
47
import java.io.IOException;
47
import java.io.PrintWriter;
48
import java.io.PrintWriter;
48
import java.io.StringWriter;
49
import java.io.StringWriter;
50
import java.util.logging.Handler;
49
import java.util.logging.Level;
51
import java.util.logging.Level;
52
import java.util.logging.LogRecord;
53
import java.util.logging.Logger;
50
import junit.framework.TestCase;
54
import junit.framework.TestCase;
51
import org.netbeans.junit.Log;
55
import org.netbeans.junit.Log;
52
56
Lines 108-113 Link Here
108
112
109
        assertCleanStackTrace(e);
113
        assertCleanStackTrace(e);
110
    }
114
    }
115
    
116
    public void testLogLevel() {
117
        Exception e = new IOException("Help");
118
        
119
        Exception result = Exceptions.attachSeverity(e, Level.FINE);
120
        assertSame(e, result);
121
122
        class H extends Handler {
123
            int cnt;
124
            
125
            @Override
126
            public void publish(LogRecord record) {
127
                assertEquals("Fine is the level", Level.FINE, record.getLevel());
128
                cnt++;
129
            }
130
131
            @Override
132
            public void flush() {
133
            }
134
135
            @Override
136
            public void close() throws SecurityException {
137
            }
138
            
139
        }
140
        
141
        H h = new H();
142
        h.setLevel(Level.ALL);
143
        Logger L = Logger.getLogger("");
144
        L.setLevel(Level.ALL);
145
        L.addHandler(h);
146
        
147
        Exceptions.printStackTrace(e);
148
        L.removeHandler(h);
149
        assertEquals("Called once", 1, h.cnt);
150
    }
111
151
112
    public void testAttachLocalizedMessage() {
152
    public void testAttachLocalizedMessage() {
113
        Exception e = new Exception("Help");
153
        Exception e = new Exception("Help");

Return to bug 190079