Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnjum Fatima2018-12-11 16:45:23 -0500
committerThomas Watson2018-12-11 21:39:18 -0500
commit7ab737ec81650ae8a497e1d05b81fdc82c1c5afc (patch)
treec989037f3150a23bd31f3ce4379a9aee134a1e0c
parenta65eb55c2c729d7d3510e30bea53c430ac51073f (diff)
downloadrt.equinox.framework-7ab737ec81650ae8a497e1d05b81fdc82c1c5afc.tar.gz
rt.equinox.framework-7ab737ec81650ae8a497e1d05b81fdc82c1c5afc.tar.xz
rt.equinox.framework-7ab737ec81650ae8a497e1d05b81fdc82c1c5afc.zip
Bug 542487 - LoggerContext.setLogLevels will throw NPE if no matching
bundle is found Change-Id: I7b47b5efd2cb9f66360cb3ee6f0cdccc52340e99 Signed-off-by: Anjum Fatima <anjum.eclipse@gmail.com> Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.osgi.tests/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.osgi.tests/pom.xml2
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java120
-rw-r--r--bundles/org.eclipse.osgi/META-INF/MANIFEST.MF2
-rwxr-xr-xbundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerContextTargetMap.java10
-rw-r--r--bundles/org.eclipse.osgi/pom.xml2
-rwxr-xr-xfeatures/org.eclipse.equinox.executable.feature/feature.xml2
-rw-r--r--features/org.eclipse.equinox.executable.feature/pom.xml2
8 files changed, 135 insertions, 7 deletions
diff --git a/bundles/org.eclipse.osgi.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/META-INF/MANIFEST.MF
index 8efe6f0fd..3072cd571 100644
--- a/bundles/org.eclipse.osgi.tests/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.osgi.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Core OSGi Tests
Bundle-SymbolicName: org.eclipse.osgi.tests;singleton:=true
-Bundle-Version: 3.13.200.qualifier
+Bundle-Version: 3.13.300.qualifier
Bundle-Vendor: Eclipse.org
Bundle-Localization: plugin
Require-Bundle:
diff --git a/bundles/org.eclipse.osgi.tests/pom.xml b/bundles/org.eclipse.osgi.tests/pom.xml
index 2cd7a09d2..e7265f173 100644
--- a/bundles/org.eclipse.osgi.tests/pom.xml
+++ b/bundles/org.eclipse.osgi.tests/pom.xml
@@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi.tests</artifactId>
- <version>3.13.200-SNAPSHOT</version>
+ <version>3.13.300-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java
index 7ccd71bee..aa1426bea 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java
@@ -182,6 +182,7 @@ public class LogReaderServiceTest extends AbstractBundleTests {
testBundle.start();
assertEquals("Wrong thread for synchronous bundle event logs.", Thread.currentThread(), logThread.get());
+
}
public void testLogServiceEventInfo() throws Exception {
@@ -335,4 +336,123 @@ public class LogReaderServiceTest extends AbstractBundleTests {
}
return count;
}
+
+ public void testLoggerContextSetLogLevelsWithBundleInstalledAndLogger() throws Exception {
+ Bundle bundle = null;
+ String loggerName = "test.logger";
+ try {
+ bundle = installer.installBundle("test.logging.a");
+ bundle.start();
+ Logger logger = log.getLogger(bundle, loggerName, Logger.class);
+ assertNotNull("Logger cannot be null", logger);
+ //Bundle is installed and a logger is associated with that bundle before setting the log level
+ setAndAssertLogLevel(bundle.getSymbolicName(), loggerName);
+
+ TestListener listener = new TestListener(bundle);
+ reader.addLogListener(listener);
+ for (LogLevel logLevel : LogLevel.values()) {
+ String message = logLevel.name() + " MESSAGE";
+ doLogging(bundle, logger, listener, logLevel, message);
+ }
+ } finally {
+ if (bundle != null) {
+ bundle.stop();
+ bundle.uninstall();
+ }
+ }
+ }
+
+ public void testLoggerContextSetLogLevelsWithBundleInstalledAndNoLogger() throws Exception {
+ Bundle bundle = null;
+ String loggerName = "test.logger";
+ try {
+ bundle = installer.installBundle("test.logging.a");
+ bundle.start();
+ //Bundle is installed but a logger is not associated with the bundle before setting the log level
+ setAndAssertLogLevel(bundle.getSymbolicName(), loggerName);
+ Logger logger = log.getLogger(bundle, loggerName, Logger.class);
+ assertNotNull("Logger cannot be null", logger);
+ TestListener listener = new TestListener(bundle);
+ reader.addLogListener(listener);
+ for (LogLevel logLevel : LogLevel.values()) {
+ String message = logLevel.name() + " MESSAGE";
+ doLogging(bundle, logger, listener, logLevel, message);
+ }
+ } finally {
+ if (bundle != null) {
+ bundle.stop();
+ bundle.uninstall();
+ }
+ }
+ }
+
+ public void testLoggerContextSetLogLevelsWithoutBundleAndLogger() throws Exception {
+ Bundle bundle = null;
+ String loggerName = "test.logger";
+ //Bundle is not installed and also the logger is not associated with the bundle before setting the log level
+ setAndAssertLogLevel("test.logging.a", loggerName);
+ try {
+ bundle = installer.installBundle("test.logging.a");
+ bundle.start();
+ Logger logger = log.getLogger(bundle, loggerName, Logger.class);
+ assertNotNull("Logger cannot be null", logger);
+ TestListener listener = new TestListener(bundle);
+ reader.addLogListener(listener);
+ for (LogLevel logLevel : LogLevel.values()) {
+ String message = logLevel.name() + " MESSAGE";
+ doLogging(bundle, logger, listener, logLevel, message);
+ }
+ } finally {
+ if (bundle != null) {
+ bundle.stop();
+ bundle.uninstall();
+ }
+ }
+ }
+
+ private void setAndAssertLogLevel(String loggerContextName, String loggerName) {
+ LoggerContext loggerContext = loggerAdmin.getLoggerContext(loggerContextName);
+ Map<String, LogLevel> logLevels = loggerContext.getLogLevels();
+ logLevels.put(loggerName, LogLevel.TRACE);
+ loggerContext.setLogLevels(logLevels);
+ assertEquals("Log levels not set for " + loggerContext.getName(), logLevels, loggerContext.getLogLevels());
+ assertEquals("Wrong effective level", LogLevel.TRACE, loggerContext.getEffectiveLogLevel(loggerName));
+ }
+
+ private void doLogging(Bundle bundle, Logger logger, TestListener listener, LogLevel logLevel, String message) throws Exception {
+ synchronized (listener) {
+ logToLogger(logger, message, logLevel);
+ listener.waitForLogEntry();
+ }
+ ExtendedLogEntry logEntry = listener.getEntryX();
+ assertEquals("Wrong message logged", message, logEntry.getMessage());
+ assertEquals("Wrong Log level", logLevel, logEntry.getLogLevel());
+ assertEquals("Wrong Logger name", logger.getName(), logEntry.getLoggerName());
+ assertEquals("Wrong bundle", bundle.getSymbolicName(), logEntry.getBundle().getSymbolicName());
+ }
+
+ private void logToLogger(Logger logger, String message, LogLevel logLevel) {
+ switch (logLevel) {
+ case AUDIT :
+ logger.audit(message);
+ break;
+ case ERROR :
+ logger.error(message);
+ break;
+ case WARN :
+ logger.warn(message);
+ break;
+ case INFO :
+ logger.info(message);
+ break;
+ case DEBUG :
+ logger.debug(message);
+ break;
+ case TRACE :
+ logger.trace(message);
+ break;
+ default :
+ fail("Unknown Log level");
+ }
+ }
}
diff --git a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF
index 31c5aca7f..25ab3347b 100644
--- a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF
@@ -101,7 +101,7 @@ Bundle-Activator: org.eclipse.osgi.internal.framework.SystemBundleActivator
Bundle-Description: %systemBundle
Bundle-Copyright: %copyright
Bundle-Vendor: %eclipse.org
-Bundle-Version: 3.13.200.qualifier
+Bundle-Version: 3.13.300.qualifier
Bundle-Localization: systembundle
Bundle-DocUrl: http://www.eclipse.org
Eclipse-ExtensibleAPI: true
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerContextTargetMap.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerContextTargetMap.java
index 0893d9393..2f6c0f832 100755
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerContextTargetMap.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerContextTargetMap.java
@@ -13,7 +13,12 @@
*******************************************************************************/
package org.eclipse.osgi.internal.log;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.eclipse.osgi.internal.log.ExtendedLogServiceFactory.EquinoxLoggerContext;
import org.osgi.framework.Bundle;
import org.osgi.framework.Version;
@@ -132,6 +137,9 @@ public class LoggerContextTargetMap {
} else {
matching = qualifiedNameToTargets.get(loggerContext.getName());
}
+ if (matching == null) {
+ return;
+ }
for (Bundle bundle : matching) {
ExtendedLogServiceImpl logService = logServices.get(bundle);
if (logService != null) {
diff --git a/bundles/org.eclipse.osgi/pom.xml b/bundles/org.eclipse.osgi/pom.xml
index dc17965a3..9c6f4b551 100644
--- a/bundles/org.eclipse.osgi/pom.xml
+++ b/bundles/org.eclipse.osgi/pom.xml
@@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi</artifactId>
- <version>3.13.200-SNAPSHOT</version>
+ <version>3.13.300-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<build>
diff --git a/features/org.eclipse.equinox.executable.feature/feature.xml b/features/org.eclipse.equinox.executable.feature/feature.xml
index c9152a1e9..c7fab6027 100755
--- a/features/org.eclipse.equinox.executable.feature/feature.xml
+++ b/features/org.eclipse.equinox.executable.feature/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.eclipse.equinox.executable"
label="%featureName"
- version="3.8.200.qualifier"
+ version="3.8.300.qualifier"
license-feature="org.eclipse.license"
license-feature-version="0.0.0">
diff --git a/features/org.eclipse.equinox.executable.feature/pom.xml b/features/org.eclipse.equinox.executable.feature/pom.xml
index 9801003b6..e01ecbd3d 100644
--- a/features/org.eclipse.equinox.executable.feature/pom.xml
+++ b/features/org.eclipse.equinox.executable.feature/pom.xml
@@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.equinox.feature</groupId>
<artifactId>org.eclipse.equinox.executable</artifactId>
- <version>3.8.200-SNAPSHOT</version>
+ <version>3.8.300-SNAPSHOT</version>
<packaging>eclipse-feature</packaging>
<build>

Back to the top