New upstream release.
Debian Janitor
2 years ago
0 | libslf4j-java (1.7.32-1) UNRELEASED; urgency=low | |
1 | ||
2 | * New upstream release. | |
3 | ||
4 | -- Debian Janitor <janitor@jelmer.uk> Fri, 20 Aug 2021 05:29:58 -0000 | |
5 | ||
0 | 6 | libslf4j-java (1.7.30-1) unstable; urgency=medium |
1 | 7 | |
2 | 8 | * New upstream release |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.30</version> | |
9 | <version>1.7.32</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>integration</artifactId> |
4 | 4 | <parent> |
5 | 5 | <groupId>org.slf4j</groupId> |
6 | 6 | <artifactId>slf4j-parent</artifactId> |
7 | <version>1.7.30</version> | |
7 | <version>1.7.32</version> | |
8 | 8 | </parent> |
9 | 9 | |
10 | 10 | <modelVersion>4.0.0</modelVersion> |
+36
-12
103 | 103 | * the message to log. Converted to {@link String} |
104 | 104 | */ |
105 | 105 | public void trace(Object message) { |
106 | logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String.valueOf(message), null, null); | |
106 | if (isTraceEnabled()) { | |
107 | logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String.valueOf(message), null, null); | |
108 | } | |
107 | 109 | } |
108 | 110 | |
109 | 111 | /** |
116 | 118 | * the exception to log |
117 | 119 | */ |
118 | 120 | public void trace(Object message, Throwable t) { |
119 | logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String.valueOf(message), null, t); | |
121 | if (isTraceEnabled()) { | |
122 | logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String.valueOf(message), null, t); | |
123 | } | |
120 | 124 | } |
121 | 125 | |
122 | 126 | /** |
127 | 131 | * the message to log. Converted to {@link String} |
128 | 132 | */ |
129 | 133 | public void debug(Object message) { |
130 | logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String.valueOf(message), null, null); | |
134 | if (isDebugEnabled()) { | |
135 | logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String.valueOf(message), null, null); | |
136 | } | |
131 | 137 | } |
132 | 138 | |
133 | 139 | /** |
140 | 146 | * the exception to log |
141 | 147 | */ |
142 | 148 | public void debug(Object message, Throwable t) { |
143 | logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String.valueOf(message), null, t); | |
149 | if (isDebugEnabled()) { | |
150 | logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String.valueOf(message), null, t); | |
151 | } | |
144 | 152 | } |
145 | 153 | |
146 | 154 | /** |
151 | 159 | * the message to log. Converted to {@link String} |
152 | 160 | */ |
153 | 161 | public void info(Object message) { |
154 | logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String.valueOf(message), null, null); | |
162 | if (isInfoEnabled()) { | |
163 | logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String.valueOf(message), null, null); | |
164 | } | |
155 | 165 | } |
156 | 166 | |
157 | 167 | /** |
164 | 174 | * the exception to log |
165 | 175 | */ |
166 | 176 | public void info(Object message, Throwable t) { |
167 | logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String.valueOf(message), null, t); | |
177 | if (isInfoEnabled()) { | |
178 | logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String.valueOf(message), null, t); | |
179 | } | |
168 | 180 | } |
169 | 181 | |
170 | 182 | /** |
175 | 187 | * the message to log. Converted to {@link String} |
176 | 188 | */ |
177 | 189 | public void warn(Object message) { |
178 | logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String.valueOf(message), null, null); | |
190 | if (isWarnEnabled()) { | |
191 | logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String.valueOf(message), null, null); | |
192 | } | |
179 | 193 | } |
180 | 194 | |
181 | 195 | /** |
188 | 202 | * the exception to log |
189 | 203 | */ |
190 | 204 | public void warn(Object message, Throwable t) { |
191 | logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String.valueOf(message), null, t); | |
205 | if (isWarnEnabled()) { | |
206 | logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String.valueOf(message), null, t); | |
207 | } | |
192 | 208 | } |
193 | 209 | |
194 | 210 | /** |
199 | 215 | * the message to log. Converted to {@link String} |
200 | 216 | */ |
201 | 217 | public void error(Object message) { |
202 | logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, null); | |
218 | if (isErrorEnabled()) { | |
219 | logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, null); | |
220 | } | |
203 | 221 | } |
204 | 222 | |
205 | 223 | /** |
212 | 230 | * the exception to log |
213 | 231 | */ |
214 | 232 | public void error(Object message, Throwable t) { |
215 | logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, t); | |
233 | if (isErrorEnabled()) { | |
234 | logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, t); | |
235 | } | |
216 | 236 | } |
217 | 237 | |
218 | 238 | /** |
223 | 243 | * the message to log. Converted to {@link String} |
224 | 244 | */ |
225 | 245 | public void fatal(Object message) { |
226 | logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, null); | |
246 | if (isErrorEnabled()) { | |
247 | logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, null); | |
248 | } | |
227 | 249 | } |
228 | 250 | |
229 | 251 | /** |
236 | 258 | * the exception to log |
237 | 259 | */ |
238 | 260 | public void fatal(Object message, Throwable t) { |
239 | logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, t); | |
261 | if (isErrorEnabled()) { | |
262 | logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, t); | |
263 | } | |
240 | 264 | } |
241 | 265 | |
242 | 266 | /** |
26 | 26 | |
27 | 27 | import static org.junit.Assert.assertFalse; |
28 | 28 | import static org.junit.Assert.assertTrue; |
29 | import static org.junit.Assert.assertEquals; | |
29 | 30 | |
30 | 31 | import org.junit.Test; |
31 | 32 | |
84 | 85 | log.fatal(null, e); |
85 | 86 | log.fatal("fatal message", e); |
86 | 87 | } |
88 | ||
89 | @Test | |
90 | public void testAvoidConvertingObjectToString() { | |
91 | Log log = LogFactory.getLog(InvokeJCLTest.class); | |
92 | Exception e = new Exception("just testing"); | |
93 | ||
94 | TestMessage fatalMsg = new TestMessage("fatal msg"); | |
95 | TestMessage errorMsg = new TestMessage("error msg"); | |
96 | TestMessage warnMsg = new TestMessage("warn msg"); | |
97 | TestMessage infoMsg = new TestMessage("info msg"); | |
98 | TestMessage debugMsg = new TestMessage("debug msg"); | |
99 | TestMessage traceMsg = new TestMessage("trace msg"); | |
100 | ||
101 | log.fatal(fatalMsg); | |
102 | log.fatal(fatalMsg, e); | |
103 | assertEquals(2, fatalMsg.invokedCount); | |
104 | ||
105 | log.error(errorMsg); | |
106 | log.error(errorMsg, e); | |
107 | assertEquals(2, errorMsg.invokedCount); | |
108 | ||
109 | log.warn(warnMsg); | |
110 | log.warn(warnMsg, e); | |
111 | assertEquals(2, warnMsg.invokedCount); | |
112 | ||
113 | log.info(infoMsg); | |
114 | log.info(infoMsg, e); | |
115 | assertEquals(2, infoMsg.invokedCount); | |
116 | ||
117 | log.debug(debugMsg); | |
118 | log.debug(debugMsg, e); | |
119 | assertEquals(0, debugMsg.invokedCount); | |
120 | ||
121 | log.trace(traceMsg); | |
122 | log.trace(traceMsg, e); | |
123 | assertEquals(0, traceMsg.invokedCount); | |
124 | } | |
125 | ||
126 | static class TestMessage { | |
127 | ||
128 | private final String msg; | |
129 | int invokedCount = 0; | |
130 | ||
131 | TestMessage(String msg) {this.msg = msg;} | |
132 | ||
133 | @Override | |
134 | public String toString() { | |
135 | invokedCount++; | |
136 | return msg; | |
137 | } | |
138 | } | |
139 | ||
87 | 140 | } |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.30</version> | |
9 | <version>1.7.32</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>jul-to-slf4j</artifactId> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.30</version> | |
9 | <version>1.7.32</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 |
14 | 14 | */ |
15 | 15 | package org.apache.log4j; |
16 | 16 | |
17 | /** | |
18 | * Skeleton implementation of ConsoleAppender | |
19 | */ | |
17 | 20 | public class ConsoleAppender extends WriterAppender { |
18 | 21 | |
22 | public ConsoleAppender() { | |
23 | } | |
24 | ||
25 | public ConsoleAppender(Layout layout) { | |
26 | } | |
27 | ||
28 | public ConsoleAppender(Layout layout, String target) { | |
29 | } | |
30 | ||
19 | 31 | } |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.30</version> | |
9 | <version>1.7.32</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>osgi-over-slf4j</artifactId> |
5 | 5 | |
6 | 6 | <groupId>org.slf4j</groupId> |
7 | 7 | <artifactId>slf4j-parent</artifactId> |
8 | <version>1.7.30</version> | |
8 | <version>1.7.32</version> | |
9 | 9 | |
10 | 10 | <packaging>pom</packaging> |
11 | 11 | <name>SLF4J</name> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.30</version> | |
9 | <version>1.7.32</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-android</artifactId> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.30</version> | |
9 | <version>1.7.32</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-api</artifactId> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.30</version> | |
9 | <version>1.7.32</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-ext</artifactId> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.30</version> | |
9 | <version>1.7.32</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-jcl</artifactId> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.30</version> | |
9 | <version>1.7.32</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-jdk14</artifactId> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.30</version> | |
9 | <version>1.7.32</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-log4j12</artifactId> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.30</version> | |
9 | <version>1.7.32</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-migrator</artifactId> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.30</version> | |
9 | <version>1.7.32</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-nop</artifactId> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.30</version> | |
9 | <version>1.7.32</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-simple</artifactId> |
156 | 156 | protected static final int LOG_LEVEL_OFF = LOG_LEVEL_ERROR + 10; |
157 | 157 | |
158 | 158 | private static boolean INITIALIZED = false; |
159 | static SimpleLoggerConfiguration CONFIG_PARAMS = null; | |
159 | static final private SimpleLoggerConfiguration CONFIG_PARAMS = new SimpleLoggerConfiguration(); | |
160 | 160 | |
161 | 161 | static void lazyInit() { |
162 | 162 | if (INITIALIZED) { |
169 | 169 | // external software might be invoking this method directly. Do not rename |
170 | 170 | // or change its semantics. |
171 | 171 | static void init() { |
172 | CONFIG_PARAMS = new SimpleLoggerConfiguration(); | |
173 | 172 | CONFIG_PARAMS.init(); |
174 | 173 | } |
175 | 174 | |
311 | 310 | throw new IllegalStateException("Unrecognized level [" + level + "]"); |
312 | 311 | } |
313 | 312 | |
313 | /** | |
314 | * To avoid intermingling of log messages and associated stack traces, the two | |
315 | * operations are done in a synchronized block. | |
316 | * | |
317 | * @param buf | |
318 | * @param t | |
319 | */ | |
314 | 320 | void write(StringBuilder buf, Throwable t) { |
315 | 321 | PrintStream targetStream = CONFIG_PARAMS.outputChoice.getTargetPrintStream(); |
316 | 322 | |
317 | targetStream.println(buf.toString()); | |
318 | writeThrowable(t, targetStream); | |
319 | targetStream.flush(); | |
323 | synchronized (CONFIG_PARAMS) { | |
324 | targetStream.println(buf.toString()); | |
325 | writeThrowable(t, targetStream); | |
326 | targetStream.flush(); | |
327 | } | |
328 | ||
320 | 329 | } |
321 | 330 | |
322 | 331 | protected void writeThrowable(Throwable t, PrintStream targetStream) { |
+128
-0
0 | /** | |
1 | * Copyright (c) 2004-2021 QOS.ch | |
2 | * All rights reserved. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining | |
5 | * a copy of this software and associated documentation files (the | |
6 | * "Software"), to deal in the Software without restriction, including | |
7 | * without limitation the rights to use, copy, modify, merge, publish, | |
8 | * distribute, sublicense, and/or sell copies of the Software, and to | |
9 | * permit persons to whom the Software is furnished to do so, subject to | |
10 | * the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be | |
13 | * included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | package org.slf4j.simple.multiThreadedExecution; | |
25 | ||
26 | import java.io.PrintStream; | |
27 | ||
28 | import org.junit.After; | |
29 | import org.junit.Before; | |
30 | import org.junit.Test; | |
31 | import org.slf4j.Logger; | |
32 | import org.slf4j.LoggerFactory; | |
33 | ||
34 | /** | |
35 | * Tests that output in multi-threaded environments is not mingled. | |
36 | * | |
37 | * See also https://jira.qos.ch/browse/SLF4J-515 | |
38 | */ | |
39 | public class MultithereadedExecutionTest { | |
40 | ||
41 | private static int THREAD_COUNT = 2; | |
42 | private static long TEST_DURATION_IN_MILLIS = 100; | |
43 | ||
44 | private Thread[] threads = new Thread[THREAD_COUNT]; | |
45 | ||
46 | private final PrintStream oldOut = System.out; | |
47 | StateCheckingPrintStream scps = new StateCheckingPrintStream(oldOut); | |
48 | ||
49 | volatile boolean signal = false; | |
50 | ||
51 | @Before | |
52 | public void setup() { | |
53 | System.setErr(scps); | |
54 | // System.setProperty(SimpleLogger.LOG_FILE_KEY, "System.err"); | |
55 | // LoggerFactoryFriend.reset(); | |
56 | } | |
57 | ||
58 | @After | |
59 | public void tearDown() throws Exception { | |
60 | // LoggerFactoryFriend.reset(); | |
61 | // System.clearProperty(SimpleLogger.LOG_FILE_KEY); | |
62 | System.setErr(oldOut); | |
63 | } | |
64 | ||
65 | @Test | |
66 | public void test() throws Throwable { | |
67 | WithException withException = new WithException(); | |
68 | Other other = new Other(); | |
69 | threads[0] = new Thread(withException); | |
70 | threads[1] = new Thread(other); | |
71 | threads[0].start(); | |
72 | threads[1].start(); | |
73 | Thread.sleep(TEST_DURATION_IN_MILLIS); | |
74 | signal = true; | |
75 | threads[0].join(); | |
76 | threads[1].join(); | |
77 | ||
78 | if (withException.throwable != null) { | |
79 | throw withException.throwable; | |
80 | } | |
81 | ||
82 | if (other.throwable != null) { | |
83 | throw other.throwable; | |
84 | } | |
85 | ||
86 | } | |
87 | ||
88 | class WithException implements Runnable { | |
89 | ||
90 | volatile Throwable throwable; | |
91 | Logger logger = LoggerFactory.getLogger(WithException.class); | |
92 | ||
93 | public void run() { | |
94 | int i = 0; | |
95 | ||
96 | while (!signal) { | |
97 | try { | |
98 | logger.info("Hello {}", i, new Throwable("i=" + i)); | |
99 | i++; | |
100 | } catch (Throwable t) { | |
101 | throwable = t; | |
102 | MultithereadedExecutionTest.this.signal = true; | |
103 | return; | |
104 | } | |
105 | } | |
106 | ||
107 | } | |
108 | } | |
109 | ||
110 | class Other implements Runnable { | |
111 | volatile Throwable throwable; | |
112 | Logger logger = LoggerFactory.getLogger(Other.class); | |
113 | ||
114 | public void run() { | |
115 | int i = 0; | |
116 | while (!signal) { | |
117 | try { | |
118 | logger.info("Other {}", i++); | |
119 | } catch (Throwable t) { | |
120 | throwable = t; | |
121 | MultithereadedExecutionTest.this.signal = true; | |
122 | return; | |
123 | } | |
124 | } | |
125 | } | |
126 | } | |
127 | } |
+141
-0
0 | /** | |
1 | * Copyright (c) 2004-2021 QOS.ch | |
2 | * All rights reserved. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining | |
5 | * a copy of this software and associated documentation files (the | |
6 | * "Software"), to deal in the Software without restriction, including | |
7 | * without limitation the rights to use, copy, modify, merge, publish, | |
8 | * distribute, sublicense, and/or sell copies of the Software, and to | |
9 | * permit persons to whom the Software is furnished to do so, subject to | |
10 | * the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be | |
13 | * included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | package org.slf4j.simple.multiThreadedExecution; | |
25 | ||
26 | import java.io.PrintStream; | |
27 | import java.util.regex.Pattern; | |
28 | ||
29 | /** | |
30 | * This PrintStream checks that output lines are in an expected order. | |
31 | * | |
32 | * @author ceki | |
33 | */ | |
34 | public class StateCheckingPrintStream extends PrintStream { | |
35 | ||
36 | enum State { | |
37 | INITIAL, UNKNOWN, HELLO, THROWABLE, AT1, AT2, OTHER; | |
38 | } | |
39 | ||
40 | volatile State currentState = State.INITIAL; | |
41 | ||
42 | public StateCheckingPrintStream(PrintStream ps) { | |
43 | super(ps); | |
44 | } | |
45 | ||
46 | public void print(String s) { | |
47 | } | |
48 | ||
49 | public void println(String s) { | |
50 | ||
51 | State next = computeState(s); | |
52 | //System.out.println(next + " " + s); | |
53 | switch (currentState) { | |
54 | case INITIAL: | |
55 | currentState = next; | |
56 | break; | |
57 | ||
58 | case UNKNOWN: | |
59 | // ignore garbage | |
60 | currentState = next; | |
61 | break; | |
62 | ||
63 | case OTHER: | |
64 | if (next == State.UNKNOWN) { | |
65 | currentState = State.UNKNOWN; | |
66 | return; | |
67 | } | |
68 | ||
69 | if (next != State.OTHER && next != State.HELLO) { | |
70 | throw badState(s, currentState, next); | |
71 | } | |
72 | currentState = next; | |
73 | break; | |
74 | ||
75 | case HELLO: | |
76 | if (next != State.THROWABLE) { | |
77 | throw badState(s, currentState, next); | |
78 | } | |
79 | currentState = next; | |
80 | break; | |
81 | case THROWABLE: | |
82 | if (next != State.AT1) { | |
83 | throw badState(s, currentState, next); | |
84 | } | |
85 | currentState = next; | |
86 | break; | |
87 | ||
88 | case AT1: | |
89 | if (next != State.AT2) { | |
90 | throw badState(s, currentState, next); | |
91 | } | |
92 | currentState = next; | |
93 | break; | |
94 | ||
95 | case AT2: | |
96 | currentState = next; | |
97 | break; | |
98 | default: | |
99 | throw new IllegalStateException("Unreachable code"); | |
100 | } | |
101 | } | |
102 | ||
103 | private IllegalStateException badState(String s, State currentState2, State next) { | |
104 | return new IllegalStateException("Unexpected state " + next + " for current state " + currentState2 + " for " + s); | |
105 | ||
106 | } | |
107 | ||
108 | String OTHER_PATTERN_STR = ".*Other \\d{1,5}"; | |
109 | String HELLO_PATTERN_STR = ".*Hello \\d{1,5}"; | |
110 | String THROWABLE_PATTERN_STR = "java.lang.Throwable: i=\\d{1,5}"; | |
111 | String AT1_PATTERN_STR = "\\s*at " + this.getClass().getPackage().getName() + ".*"; | |
112 | String AT2_PATTERN_STR = "\\s*at " + ".*Thread.java.*"; | |
113 | ||
114 | Pattern PATTERN_OTHER = Pattern.compile(OTHER_PATTERN_STR); | |
115 | Pattern PATTERN_HELLO = Pattern.compile(HELLO_PATTERN_STR); | |
116 | Pattern PATTERN_THROWABLE = Pattern.compile(THROWABLE_PATTERN_STR); | |
117 | Pattern PATTERN_AT1 = Pattern.compile(AT1_PATTERN_STR); | |
118 | Pattern PATTERN_AT2 = Pattern.compile(AT2_PATTERN_STR); | |
119 | ||
120 | private State computeState(String s) { | |
121 | ||
122 | if (PATTERN_OTHER.matcher(s).matches()) { | |
123 | return State.OTHER; | |
124 | } else if (PATTERN_HELLO.matcher(s).matches()) { | |
125 | return State.HELLO; | |
126 | } else if (PATTERN_THROWABLE.matcher(s).matches()) { | |
127 | return State.THROWABLE; | |
128 | } else if (PATTERN_AT1.matcher(s).matches()) { | |
129 | return State.AT1; | |
130 | } else if (PATTERN_AT2.matcher(s).matches()) { | |
131 | return State.AT2; | |
132 | } else { | |
133 | return State.UNKNOWN; | |
134 | } | |
135 | } | |
136 | ||
137 | public void println(Object o) { | |
138 | println(o.toString()); | |
139 | } | |
140 | }⏎ |