Github user gerdogdu commented on a diff in the pull request:
https://github.com/apache/tomee/pull/332#discussion_r244579276
--- Diff:
container/openejb-core/src/main/java/org/apache/openejb/OpenEjbContainer.java
---
@@ -71,57 +50,74 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
+import java.util.*;
import java.util.logging.LogManager;
import static org.apache.openejb.cdi.ScopeHelper.startContexts;
import static org.apache.openejb.cdi.ScopeHelper.stopContexts;
/**
- * @version $Rev$ $Date$
+ * Embeddable {@link EJBContainer} implementation based
+ * on OpenEJB container.
*/
public final class OpenEjbContainer extends EJBContainer {
+
static {
// if tomee embedded was ran we'll lost log otherwise
- final String logManger =
JavaSecurityManagers.getSystemProperty("java.util.logging.manager");
- if (logManger != null) {
+ final String logManager =
JavaSecurityManagers.getSystemProperty("java.util.logging.manager");
+ if (logManager != null) {
try {
-
Thread.currentThread().getContextClassLoader().loadClass(logManger);
+
Thread.currentThread().getContextClassLoader().loadClass(logManager);
} catch (final Exception ignored) {
- final Field field;
+ Field field = null;
+ boolean accessible = false;
try {
field = LogManager.class.getDeclaredField("manager");
- field.setAccessible(true);
- field.set(null, new
JuliLogStreamFactory.OpenEJBLogManager());
+ if(field != null){
+ accessible = field.isAccessible();
+ field.setAccessible(true);
+ field.set(null, new
JuliLogStreamFactory.OpenEJBLogManager());
+ }
+
} catch (final Exception ignore) {
// ignore
+ }finally{
+ if(field != null){
+ field.setAccessible(accessible);
--- End diff --
> This code you are touching is used by everything and is rarely touched.
You are introducing extensive changes. Prudence advises to also add new tests
to make sure the changes are ok.
I did not change the logic of the class, just separated the big method to
smaller parts for the purpose of readable and understandable code.
The idea is that TomEE community accept that the code is indeed unreadable
and then can accept my patch and then if there needs to have any further
changes, we can continue to patch or update.
I think that this is a normal procedure for working with community. This is
a simple change. For example, if you want to look for an extensive change, it
is a microprofile addition to the core TomEE codebase :)
---