Skip to content

Commit 366a01f

Browse files
committed
Fixed potential NPE in annotation scanning code
Conflicts: CHANGELOG.txt
1 parent 5a45ca0 commit 366a01f

2 files changed

Lines changed: 61 additions & 52 deletions

File tree

‎CHANGELOG.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ Regression Impact:
1111
Search: <view-id>\s*([^<]+?)\s*</view-id>
1212
Replace: <view-id value="$1" />
1313

14+
------------------------------------
15+
VERSION 3.3.3
16+
------------------------------------
17+
18+
Bugfixes:
19+
* Fixed potential NullPointerException in annotation scanning code
1420

1521
------------------------------------
1622
VERSION 3.3.1

‎core/src/main/java/com/ocpsoft/pretty/faces/config/annotation/WebClassesFinder.java‎

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -113,85 +113,88 @@ protected void processDirectory(URL classesFolderUrl, URL directoryUrl, PrettyAn
113113
// call getResourcePaths to get directory entries
114114
Set<?> paths = servletContext.getResourcePaths(CLASSES_FOLDER+relativeDirectoryName);
115115

116-
// loop over all entries of the directory
117-
for (Object relativePath : paths)
118-
{
119-
120-
// get full URL for this entry
121-
URL entryUrl = servletContext.getResource(relativePath.toString());
116+
if (paths != null) {
122117

123-
// if this URL ends with .class it is a Java class
124-
if (entryUrl.getPath().endsWith(".class"))
118+
// loop over all entries of the directory
119+
for (Object relativePath : paths)
125120
{
126121

127-
// the name of the entry relative to the '/WEB-INF/classes/' folder
128-
String entryRelativeName = getPathRelativeToClassesFolder(entryUrl.getPath(), classesFolderPath);
129-
130-
// build class name from relative name
131-
String className = getClassName(entryRelativeName);
122+
// get full URL for this entry
123+
URL entryUrl = servletContext.getResource(relativePath.toString());
132124

133-
// check filter
134-
if (mustProcessClass(className) && !processedClasses.contains(className))
125+
// if this URL ends with .class it is a Java class
126+
if (entryUrl.getPath().endsWith(".class"))
135127
{
136128

137-
// mark this class as processed
138-
processedClasses.add(className);
129+
// the name of the entry relative to the '/WEB-INF/classes/' folder
130+
String entryRelativeName = getPathRelativeToClassesFolder(entryUrl.getPath(), classesFolderPath);
139131

140-
// the class file stream
141-
InputStream classFileStream = null;
132+
// build class name from relative name
133+
String className = getClassName(entryRelativeName);
142134

143-
// close the stream in finally block
144-
try
135+
// check filter
136+
if (mustProcessClass(className) && !processedClasses.contains(className))
145137
{
146138

147-
/*
148-
* Try to open the .class file. If an IOException is thrown,
149-
* we will scan it anyway.
150-
*/
139+
// mark this class as processed
140+
processedClasses.add(className);
141+
142+
// the class file stream
143+
InputStream classFileStream = null;
144+
145+
// close the stream in finally block
151146
try
152147
{
153-
classFileStream = entryUrl.openStream();
154-
}
155-
catch (IOException e)
156-
{
157-
if (log.isDebugEnabled())
148+
149+
/*
150+
* Try to open the .class file. If an IOException is thrown,
151+
* we will scan it anyway.
152+
*/
153+
try
158154
{
159-
log.debug("Cound not obtain InputStream for class file: "+entryUrl.toString(), e);
155+
classFileStream = entryUrl.openStream();
156+
}
157+
catch (IOException e)
158+
{
159+
if (log.isDebugEnabled())
160+
{
161+
log.debug("Cound not obtain InputStream for class file: " + entryUrl.toString(), e);
162+
}
160163
}
161-
}
162164

163-
// analyze the class (with or without classFileStream)
164-
processClass(className, classFileStream, handler);
165+
// analyze the class (with or without classFileStream)
166+
processClass(className, classFileStream, handler);
165167

166-
}
167-
finally
168-
{
169-
try
168+
}
169+
finally
170170
{
171-
if (classFileStream != null)
171+
try
172172
{
173-
classFileStream.close();
173+
if (classFileStream != null)
174+
{
175+
classFileStream.close();
176+
}
174177
}
175-
}
176-
catch (IOException e)
177-
{
178-
if (log.isDebugEnabled())
178+
catch (IOException e)
179179
{
180-
log.debug("Failed to close input stream: " + e.getMessage());
180+
if (log.isDebugEnabled())
181+
{
182+
log.debug("Failed to close input stream: " + e.getMessage());
183+
}
181184
}
182185
}
183186
}
184-
}
185187

186-
}
188+
}
187189

188-
// if this URL ends with a slash, its a directory
189-
if (entryUrl.getPath().endsWith("/"))
190-
{
190+
// if this URL ends with a slash, its a directory
191+
if (entryUrl.getPath().endsWith("/"))
192+
{
191193

192-
// walk down the directory
193-
processDirectory(classesFolderUrl, entryUrl, handler);
194+
// walk down the directory
195+
processDirectory(classesFolderUrl, entryUrl, handler);
194196

197+
}
195198
}
196199
}
197200
}

0 commit comments

Comments
 (0)