@@ -65,7 +65,8 @@ static Optional<Path> createDictionaryFile(Method method) throws IOException {
6565 List <DictionaryFile > fileDictionaries =
6666 AnnotationSupport .findRepeatableAnnotations (method , DictionaryFile .class );
6767
68- return FuzzerDictionary .createDictionaryFile (inlineDictionaries , fileDictionaries );
68+ return FuzzerDictionary .createDictionaryFile (
69+ inlineDictionaries , fileDictionaries , method .getDeclaringClass ());
6970 }
7071
7172 /**
@@ -74,17 +75,20 @@ static Optional<Path> createDictionaryFile(Method method) throws IOException {
7475 *
7576 * @param inline list of {@link DictionaryEntries}
7677 * @param files list of {@link DictionaryFile}
78+ * @param declaringClass class containing the method with these annotations
7779 * @return Optional of dictionaryPath if created
7880 * @throws IOException
7981 */
8082 private static Optional <Path > createDictionaryFile (
81- List <DictionaryEntries > inline , List <DictionaryFile > files ) throws IOException {
83+ List <DictionaryEntries > inline , List <DictionaryFile > files , Class <?> declaringClass )
84+ throws IOException {
8285 int sources = inline .size () + files .size ();
8386 if (sources == 0 ) {
8487 return Optional .empty ();
8588 }
8689
87- Stream <String > joined = Stream .concat (getInlineTokens (inline ), getFileTokens (files ));
90+ Stream <String > joined =
91+ Stream .concat (getInlineTokens (inline ), getFileTokens (files , declaringClass ));
8892
8993 Path p = Files .createTempFile (DICTIONARY_PREFIX , DICTIONARY_SUFFIX );
9094 p .toFile ().deleteOnExit ();
@@ -120,26 +124,21 @@ private static Stream<String> getInlineTokens(List<DictionaryEntries> inline) {
120124 /**
121125 * Gets the individual lines from each of the specified dictionary files
122126 *
123- * @param files List of {@link DictionaryFile} annotations indicating which files to use
127+ * @param files list of {@link DictionaryFile} annotations indicating which files to use
128+ * @param declaringClass class containing the method with these annotations
124129 * @return stream of all lines from each of the files
125130 */
126- private static Stream <String > getFileTokens (List <DictionaryFile > files ) {
131+ private static Stream <String > getFileTokens (List <DictionaryFile > files , Class <?> declaringClass ) {
127132 return files .stream ()
128133 .map (DictionaryFile ::resourcePath )
129- .map (FuzzerDictionary :: tokensFromResource )
134+ .map (resourcePath -> tokensFromResource ( resourcePath , declaringClass ) )
130135 .flatMap (List ::stream );
131136 }
132137
133- private static List <String > tokensFromResource (String absoluteResourcePath ) {
134- if (absoluteResourcePath .startsWith ("/" )) {
135- throw new IllegalArgumentException (
136- String .format (
137- "absolute resource path is must not have leading /: %s" , absoluteResourcePath ));
138- }
139- try (InputStream resourceFile =
140- FuzzerDictionary .class .getClassLoader ().getResourceAsStream (absoluteResourcePath )) {
138+ private static List <String > tokensFromResource (String resourcePath , Class <?> declaringClass ) {
139+ try (InputStream resourceFile = declaringClass .getResourceAsStream (resourcePath )) {
141140 if (resourceFile == null ) {
142- throw new FileNotFoundException (absoluteResourcePath );
141+ throw new FileNotFoundException (resourcePath );
143142 }
144143 List <String > tokens ;
145144 try (BufferedReader reader = new BufferedReader (new InputStreamReader (resourceFile ))) {
0 commit comments