File tree Expand file tree Collapse file tree
main/scala/com/twitter/app Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,8 +9,16 @@ Unreleased
99API Changes:
1010
1111 * util-class-preloader: This library has been removed since it deprecated. We
12- no longer recommend that people do this. ``PHAB_ID=D174250``
12+ no longer recommend that people do this. ``PHAB_ID=D174250``
1313
14+ Bug Fixes:
15+
16+ * util-app: Fix issue where in some environments, `URLClassLoader#getURLs` can
17+ return null, failing LoadService from initializing properly
18+ (see: https://github.com/google/guava/issues/2239). The `URLClassLoader` javadoc
19+ is not clear if a null can be returned when calling `URLClassLoader#getURLs` and for
20+ at least one application server, the default returned is null, thus we should be more
21+ resilient against this possibility. Fixes Finagle #695. ``PHAB_ID=D181152``
1422
1523Deprecations:
1624
Original file line number Diff line number Diff line change @@ -61,16 +61,22 @@ private[app] sealed abstract class ClassPath[CpInfo <: ClassPath.Info] {
6161 buf
6262 }
6363
64- private [this ] def getEntries (loader : ClassLoader ): Seq [(URI , ClassLoader )] = {
64+ // package protected for testing
65+ private [app] def getEntries (loader : ClassLoader ): Seq [(URI , ClassLoader )] = {
6566 val ents = mutable.Buffer [(URI , ClassLoader )]()
6667 val parent = loader.getParent
6768 if (parent != null )
6869 ents ++= getEntries(parent)
6970
7071 loader match {
7172 case urlLoader : URLClassLoader =>
72- for (url <- urlLoader.getURLs) {
73- ents += (url.toURI -> loader)
73+ Option (urlLoader.getURLs) match {
74+ case Some (urls) =>
75+ urls.foreach { url =>
76+ if (url != null )
77+ ents += (url.toURI -> loader)
78+ }
79+ case _ =>
7480 }
7581 case _ =>
7682 }
Original file line number Diff line number Diff line change 1+ package com .twitter .app
2+
3+ import java .net .URLClassLoader
4+ import org .mockito .Mockito ._
5+ import org .scalatest .FunSuite
6+ import org .scalatest .mockito .MockitoSugar
7+
8+ class ClassPathTest extends FunSuite with MockitoSugar {
9+
10+ test(" Null URL[] URLClassloader" ) {
11+ val classLoader = mock[URLClassLoader ]
12+ when(classLoader.getURLs).thenReturn(null )
13+
14+ val classPath = new LoadServiceClassPath ()
15+ val entries = classPath.getEntries(classLoader)
16+ assert(entries.isEmpty)
17+ }
18+
19+ test(" Null entry in URL[] from URLClassloader" ) {
20+ val urls = Array [java.net.URL ](null )
21+
22+ val classLoader = mock[URLClassLoader ]
23+ when(classLoader.getURLs).thenReturn(urls)
24+
25+ val classPath = new LoadServiceClassPath ()
26+ val entries = classPath.getEntries(classLoader)
27+ assert(entries.isEmpty)
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments