From 5b4f9edc860a699fc2e62fff99dec11d21ec0d11 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 1 Jun 2017 10:58:00 +0100 Subject: [PATCH] Restore original TCCL in PropertiesLauncherTests Calling launch of PropertiesLauncherTests sets the thread context class loader to an instance of LaunchedURLClassLoader. To avoid this class loader being used beyond the scope of the test and launcher that created it, this commit updates PropertiesLauncherTests to capture the TCCL before each test and restore it after each test. Closes gh-9378 --- .../boot/loader/PropertiesLauncherTests.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java index c8e8083e41..d37b75a800 100644 --- a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java +++ b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,8 +53,11 @@ public class PropertiesLauncherTests { @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); + private ClassLoader contextClassLoader; + @Before public void setup() throws IOException { + this.contextClassLoader = Thread.currentThread().getContextClassLoader(); MockitoAnnotations.initMocks(this); System.setProperty("loader.home", new File("src/test/resources").getAbsolutePath()); @@ -62,6 +65,7 @@ public class PropertiesLauncherTests { @After public void close() { + Thread.currentThread().setContextClassLoader(this.contextClassLoader); System.clearProperty("loader.home"); System.clearProperty("loader.path"); System.clearProperty("loader.main");