Author: rgoers
Date: Wed Aug  8 06:28:55 2012
New Revision: 1370673

URL: http://svn.apache.org/viewvc?rev=1370673&view=rev
Log:
Fix Log4J2-64 - Fix compilation errors under Java 7

Modified:
    
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/AbstractManager.java
    
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
    
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
    
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
    
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
    
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
    
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/DatagramSocketManager.java
    
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java
    
logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeAvroAppender.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/AbstractManager.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/AbstractManager.java?rev=1370673&r1=1370672&r2=1370673&view=diff
==============================================================================
--- 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/AbstractManager.java
 (original)
+++ 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/AbstractManager.java
 Wed Aug  8 06:28:55 2012
@@ -42,7 +42,7 @@ public abstract class AbstractManager {
 
     private String name;
 
-    private int count;
+    protected int count;
 
     protected AbstractManager(String name) {
         this.name = name;

Modified: 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java?rev=1370673&r1=1370672&r2=1370673&view=diff
==============================================================================
--- 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
 (original)
+++ 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
 Wed Aug  8 06:28:55 2012
@@ -87,8 +87,8 @@ public final class ConsoleAppender exten
     private static OutputStreamManager getManager(Target target) {
         String type = target.name();
         OutputStream os = target == Target.SYSTEM_OUT ? System.out : 
System.err;
-        OutputStreamManager manager = 
OutputStreamManager.getManager(target.name(), factory,
-            new FactoryData(os, type));
+        OutputStreamManager manager = 
OutputStreamManager.getManager(target.name(), new FactoryData(os, type), factory
+        );
         return manager;
     }
 

Modified: 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java?rev=1370673&r1=1370672&r2=1370673&view=diff
==============================================================================
--- 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
 (original)
+++ 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
 Wed Aug  8 06:28:55 2012
@@ -55,7 +55,7 @@ public class FileManager extends OutputS
         if (locking && bufferedIO) {
             locking = false;
         }
-        return (FileManager) getManager(fileName, factory, new 
FactoryData(append, locking, bufferedIO));
+        return (FileManager) getManager(fileName, new FactoryData(append, 
locking, bufferedIO), factory);
     }
 
     protected synchronized void write(byte[] bytes, int offset, int length)  {

Modified: 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java?rev=1370673&r1=1370672&r2=1370673&view=diff
==============================================================================
--- 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
 (original)
+++ 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
 Wed Aug  8 06:28:55 2012
@@ -36,13 +36,14 @@ public class OutputStreamManager extends
 
     /**
      * Create a Manager.
+     *
      * @param name The name of the stream to manage.
-     * @param factory The factory to use to create the Manager.
      * @param data The data to pass to the Manager.
+     * @param factory The factory to use to create the Manager.
      * @return An OutputStreamManager.
      */
-    public static OutputStreamManager getManager(String name, 
ManagerFactory<OutputStreamManager, Object> factory,
-                                                 Object data) {
+    public static OutputStreamManager getManager(String name, Object data,
+                                                 
ManagerFactory<OutputStreamManager, Object> factory) {
         return AbstractManager.getManager(name, factory, data);
     }
 

Modified: 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java?rev=1370673&r1=1370672&r2=1370673&view=diff
==============================================================================
--- 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
 (original)
+++ 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
 Wed Aug  8 06:28:55 2012
@@ -61,8 +61,8 @@ public class RollingFileManager extends 
     public static RollingFileManager getFileManager(String fileName, String 
pattern, boolean append,
                                                     boolean bufferedIO) {
 
-        return (RollingFileManager) getManager(fileName, factory, new 
FactoryData(pattern, append,
-            bufferedIO));
+        return (RollingFileManager) getManager(fileName, new 
FactoryData(pattern, append,
+            bufferedIO), factory);
     }
 
     protected synchronized void write(byte[] bytes, int offset, int length) {

Modified: 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java?rev=1370673&r1=1370672&r2=1370673&view=diff
==============================================================================
--- 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
 (original)
+++ 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
 Wed Aug  8 06:28:55 2012
@@ -43,10 +43,10 @@ public class ThrowableProxy extends Thro
     private static final org.apache.logging.log4j.Logger LOGGER = 
StatusLogger.getLogger();
 
     private static Method getSuppressed;
+    private static Method addSuppressed;
 
     private final Throwable throwable;
     private final ThrowableProxy cause;
-    private final ThrowableProxy[] suppressed;
     private int commonElementCount;
 
     private final StackTracePackageElement[] callerPackageData;
@@ -68,7 +68,7 @@ public class ThrowableProxy extends Thro
         callerPackageData = resolvePackageData(stack, map, null, 
throwable.getStackTrace());
         this.cause = (throwable.getCause() == null) ? null :
             new ThrowableProxy(throwable, stack, map, throwable.getCause());
-        suppressed = getSuppressed(throwable);
+        setSuppressed(throwable);
     }
 
     /**
@@ -84,7 +84,7 @@ public class ThrowableProxy extends Thro
         callerPackageData = resolvePackageData(stack, map, 
parent.getStackTrace(), cause.getStackTrace());
         this.cause = (throwable.getCause() == null) ? null :
             new ThrowableProxy(parent, stack, map, throwable.getCause());
-        suppressed = getSuppressed(throwable);
+        setSuppressed(throwable);
     }
 
 
@@ -108,22 +108,6 @@ public class ThrowableProxy extends Thro
         return cause;
     }
 
-    /**
-     * Added in Java 7.
-     * @param exception A Throwable that was suppressed.
-     */
-    public void addSuppressed(Throwable exception) {
-        throw new UnsupportedOperationException("Cannot add suppressed 
exceptions to a ThrowableProxy");
-    }
-
-    /**
-     * Added in Java 7.
-     * @return Any suppressed exceptions.
-     */
-    public Throwable[] getSuppressed() {
-        return suppressed;
-    }
-
     @Override
     public Throwable initCause(Throwable throwable) {
         throw new IllegalStateException("Cannot set the cause on a 
ThrowableProxy");
@@ -209,6 +193,7 @@ public class ThrowableProxy extends Thro
      * @return The formatted suppressed Throwables.
      */
     public String getSuppressedStackTrace() {
+        ThrowableProxy[] suppressed = getSuppressedProxies();
         if (suppressed == null || suppressed.length == 0) {
             return "";
         }
@@ -427,6 +412,8 @@ public class ThrowableProxy extends Thro
         for (Method method : methods) {
             if (method.getName().equals("getSuppressed")) {
                 getSuppressed = method;
+            } else if (method.getName().equals("addSuppressed")) {
+                addSuppressed = method;
             }
         }
     }
@@ -463,22 +450,29 @@ public class ThrowableProxy extends Thro
         }
     }
 
-    private ThrowableProxy[] getSuppressed(Throwable throwable) {
-        ThrowableProxy[] supp = null;
+    private ThrowableProxy[] getSuppressedProxies() {
         if (getSuppressed != null) {
             try {
+                return (ThrowableProxy[]) getSuppressed.invoke(this, null);
+            } catch (Exception ex) {
+                return null;
+            }
+        }
+        return null;
+    }
+
+    private void setSuppressed(Throwable throwable) {
+        if (getSuppressed != null && addSuppressed != null) {
+            try {
                 Throwable[] array = (Throwable[]) 
getSuppressed.invoke(throwable, null);
-                supp = new ThrowableProxy[array.length];
                 int i = 0;
                 for (Throwable t : array) {
-                    supp[i] = new ThrowableProxy(t);
-                    ++i;
+                    addSuppressed.invoke(this, new ThrowableProxy(t));
                 }
             } catch (Exception ex) {
                 //
             }
         }
-        return supp;
     }
 
     /**

Modified: 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/DatagramSocketManager.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/DatagramSocketManager.java?rev=1370673&r1=1370672&r2=1370673&view=diff
==============================================================================
--- 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/DatagramSocketManager.java
 (original)
+++ 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/DatagramSocketManager.java
 Wed Aug  8 06:28:55 2012
@@ -51,8 +51,8 @@ public class DatagramSocketManager exten
         if (port <= 0) {
             throw new IllegalArgumentException("A port value is required");
         }
-        return (DatagramSocketManager) getManager("UDP:" + host + ":" + port, 
factory,
-            new FactoryData(host, port));
+        return (DatagramSocketManager) getManager("UDP:" + host + ":" + port, 
new FactoryData(host, port), factory
+        );
     }
 
     /**

Modified: 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java?rev=1370673&r1=1370672&r2=1370673&view=diff
==============================================================================
--- 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java
 (original)
+++ 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java
 Wed Aug  8 06:28:55 2012
@@ -85,7 +85,7 @@ public class TCPSocketManager extends Ab
         if (delay == 0) {
             delay = DEFAULT_RECONNECTION_DELAY;
         }
-        return (TCPSocketManager) getManager("TCP:" + host + ":" + port, 
factory, new FactoryData(host, port, delay));
+        return (TCPSocketManager) getManager("TCP:" + host + ":" + port, new 
FactoryData(host, port, delay), factory);
     }
 
     @Override

Modified: 
logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeAvroAppender.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeAvroAppender.java?rev=1370673&r1=1370672&r2=1370673&view=diff
==============================================================================
--- 
logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeAvroAppender.java
 (original)
+++ 
logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeAvroAppender.java
 Wed Aug  8 06:28:55 2012
@@ -27,6 +27,10 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.layout.RFC5424Layout;
 
 import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.Enumeration;
 
 /**
  * An Appender that uses the Avro protocol to route events to Flume.
@@ -145,7 +149,7 @@ public final class FlumeAvroAppender ext
 
         String hostname;
         try {
-            hostname = InetAddress.getLocalHost().getHostName();
+            hostname = getHostName();
         } catch (Exception ex) {
             LOGGER.error("Unable to determine local hostname", ex);
             return null;
@@ -180,4 +184,29 @@ public final class FlumeAvroAppender ext
         return new FlumeAvroAppender(name, filter, layout,  handleExceptions, 
hostname, includes,
             excludes, required, mdcPrefix, eventPrefix, compress, 
reconnectDelay, retries, factory, manager);
     }
+
+    private static String getHostName() throws Exception {
+        try {
+            return InetAddress.getLocalHost().getHostName();
+        } catch (Exception ex) {
+            // Could not locate host the easy way.
+        }
+
+        Enumeration<NetworkInterface> interfaces = 
NetworkInterface.getNetworkInterfaces();
+        while (interfaces.hasMoreElements()) {
+            NetworkInterface nic = interfaces.nextElement();
+            Enumeration<InetAddress> addresses = nic.getInetAddresses();
+            while (addresses.hasMoreElements()) {
+                InetAddress address = addresses.nextElement();
+                if (!address.isLoopbackAddress()) {
+                    String hostname = address.getHostName();
+                    if (hostname != null) {
+                        return hostname;
+                    }
+                }
+            }
+        }
+        throw new UnknownHostException("Unable to determine host name");
+
+    }
 }

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1370673&r1=1370672&r2=1370673&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Wed Aug  8 06:28:55 2012
@@ -23,7 +23,10 @@
 
   <body>
     <release version="2.0-alpha2" date="TBD" description="Bug fixes and minor 
enhancements">
-      <action issue="LOG4J2-65" dev="rgoers">
+      <action issue="LOG4J2-64" dev="rgoers" type="fix">
+        Fix compilation problems in Java 7.
+      </action>
+      <action issue="LOG4J2-65" dev="rgoers" type="fix">
         Allow variable substitution on the configuration attributes and on the 
root log level.
       </action>
     </release>


Reply via email to