diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java index 75fbe597df..8b21f8af27 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java @@ -22,7 +22,6 @@ import java.io.File; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; -import java.net.URI; import java.security.AccessController; import java.security.PrivilegedExceptionAction; import java.util.ArrayList; @@ -1425,10 +1424,7 @@ public class ConfigurationImpl implements Configuration, Serializable { */ private File subFolder(String subFolder) { try { - // Resolve wont work without "/" as the last character - URI artemisHome = new URI(getBrokerInstance().toURI() + "/"); - URI relative = artemisHome.resolve(subFolder); - return new File(relative.getPath()); + return getBrokerInstance().toPath().resolve(subFolder).toFile(); } catch (Exception e) { throw new RuntimeException(e); diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java index 1fdcdbdf24..447d51bb9b 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java @@ -16,6 +16,8 @@ */ package org.apache.activemq.artemis.core.config.impl; +import java.io.File; + import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.core.config.Configuration; @@ -483,6 +485,68 @@ public class ConfigurationImplTest extends ActiveMQTestBase { Assert.assertTrue(conf.equals(conf2)); } + @Test + public void testResolvePath() throws Throwable { + // Validate that the resolve method will work even with artemis.instance doesn't exist + + String oldProperty = System.getProperty("artemis.instance"); + + try { + System.setProperty("artemis.instance", "/tmp/" + RandomUtil.randomString()); + ConfigurationImpl configuration = new ConfigurationImpl(); + configuration.setJournalDirectory("./data-journal"); + File journalLocation = configuration.getJournalLocation(); + Assert.assertFalse("This path shouldn't resolve to a real folder", journalLocation.exists()); + } + finally { + if (oldProperty == null) { + System.clearProperty("artemis.instance"); + } + else { + System.setProperty("artemis.instance", oldProperty); + } + } + + } + + @Test + public void testAbsolutePath() throws Throwable { + // Validate that the resolve method will work even with artemis.instance doesn't exist + + String oldProperty = System.getProperty("artemis.instance"); + + File tempFolder = null; + try { + System.setProperty("artemis.instance", "/tmp/" + RandomUtil.randomString()); + tempFolder = File.createTempFile("journal-folder", ""); + tempFolder.delete(); + + tempFolder = new File(tempFolder.getAbsolutePath()); + tempFolder.mkdirs(); + + System.out.println("TempFolder = " + tempFolder.getAbsolutePath()); + + ConfigurationImpl configuration = new ConfigurationImpl(); + configuration.setJournalDirectory(tempFolder.getAbsolutePath()); + File journalLocation = configuration.getJournalLocation(); + + Assert.assertTrue(journalLocation.exists()); + } + finally { + if (oldProperty == null) { + System.clearProperty("artemis.instance"); + } + else { + System.setProperty("artemis.instance", oldProperty); + } + + if (tempFolder != null) { + tempFolder.delete(); + } + } + + } + @Override @Before public void setUp() throws Exception {