6
6
import net .bytebuddy .matcher .ElementMatcher ;
7
7
import net .bytebuddy .matcher .ElementMatchers ;
8
8
9
+ import java .util .AbstractMap ;
9
10
import java .util .List ;
10
11
import java .util .Map ;
11
12
import java .util .Set ;
@@ -122,29 +123,27 @@ static ElementMatcher<MethodDescription> getMethodsMatcher(
122
123
* This map contains the methods which can read files. The map keys represent class names,
123
124
* and the values are lists of method names that are considered to be file read operations.
124
125
*/
125
- public static final Map <String , List <String >> methodsWhichCanReadFiles = Map .of (
126
- // TODO Markus: Currently the methods which can read are not properly instrumented
127
- "java.io.FileInputStream" ,
128
- List .of ("<init>" , "read" , "open" ),
129
- "java.io.RandomAccessFile" ,
130
- List .of ("<init>" , "read" , "readFully" , "readLine" , "readBoolean" , "readByte" , "readChar" , "readDouble" ,
131
- "readFloat" , "readInt" , "readLong" , "readShort" , "readUnsignedByte" , "readUnsignedShort" ),
132
- "java.io.UnixFileSystem" ,
133
- List .of ("getBooleanAttributes0" , "getSpace" , "canonicalize0" ),
134
- "java.io.WinNTFileSystem" ,
135
- List .of ("getBooleanAttributes" , "canonicalize" , "getLastModifiedTime" , "getSpace" ),
136
- "java.io.Win32FileSystem" ,
137
- List .of ("getBooleanAttributes" , "canonicalize" , "getLastModifiedTime" , "getSpace" ),
138
- "java.nio.file.Files" ,
139
- List .of ("readAttributes" , "readAllBytes" , "readAllLines" , "readString" , "read" , "newInputStream" , "lines" ),
140
- "java.io.FileReader" ,
141
- List .of ("<init>" , "read" , "readLine" ),
142
- "java.io.BufferedReader" ,
143
- List .of ("lines" ),
144
- "java.nio.channels.FileChannel" ,
145
- List .of ("open" ),
146
- "java.nio.file.spi.FileSystemProvider" ,
147
- List .of ("newFileChannel" )
126
+ public static final Map <String , List <String >> methodsWhichCanReadFiles = Map .ofEntries (
127
+ new AbstractMap .SimpleEntry <>("java.io.FileInputStream" ,
128
+ List .of ("<init>" , "read" , "open" )),
129
+ new AbstractMap .SimpleEntry <>("java.io.RandomAccessFile" ,
130
+ List .of ("<init>" )),
131
+ new AbstractMap .SimpleEntry <>("java.io.UnixFileSystem" ,
132
+ List .of ("getBooleanAttributes0" , "getSpace" , "canonicalize0" )),
133
+ new AbstractMap .SimpleEntry <>("java.io.WinNTFileSystem" ,
134
+ List .of ("getBooleanAttributes" , "canonicalize" , "getLastModifiedTime" , "getSpace" )),
135
+ new AbstractMap .SimpleEntry <>("java.io.Win32FileSystem" ,
136
+ List .of ("getBooleanAttributes" , "canonicalize" , "getLastModifiedTime" , "getSpace" )),
137
+ new AbstractMap .SimpleEntry <>("java.nio.file.Files" ,
138
+ List .of ("readAttributes" , "readAllBytes" , "readAllLines" , "readString" , "read" , "newInputStream" , "lines" )),
139
+ new AbstractMap .SimpleEntry <>("java.io.FileReader" ,
140
+ List .of ("<init>" , "read" , "readLine" )),
141
+ new AbstractMap .SimpleEntry <>("java.io.BufferedReader" ,
142
+ List .of ("lines" )),
143
+ new AbstractMap .SimpleEntry <>("sun.nio.ch.FileChannelImpl" ,
144
+ List .of ("open" , "read" , "readFully" , "readDirect" , "readIntoNativeBuffer" )),
145
+ new AbstractMap .SimpleEntry <>("java.nio.file.spi.FileSystemProvider" ,
146
+ List .of ("newFileChannel" ))
148
147
);
149
148
//</editor-fold>
150
149
@@ -153,24 +152,26 @@ static ElementMatcher<MethodDescription> getMethodsMatcher(
153
152
* This map contains the methods which can overwrite files. The map keys represent class names,
154
153
* and the values are lists of method names that are considered to be file overwrite operations.
155
154
*/
156
- public static final Map <String , List <String >> methodsWhichCanOverwriteFiles = Map .of (
157
- "java.io.FileOutputStream" ,
158
- List .of ("<init>" ),
159
- "java.io.RandomAccessFile" ,
160
- List .of ("write" , "writeBoolean" , "writeByte" , "writeBytes" , "writeChar" , "writeChars" , "writeDouble" , "writeFloat" , "writeInt" , "writeLong" , "writeShort" ),
161
- "java.io.UnixFileSystem" ,
162
- List .of ("setLastModifiedTime" , "createFileExclusively" , "delete0" , "createDirectory" ),
163
- "java.io.WinNTFileSystem" ,
164
- List .of ("createFileExclusively" , "delete" , "setLastModifiedTime" , "createDirectory" ),
165
- "java.io.Win32FileSystem" ,
166
- List .of ("createFileExclusively" , "delete" , "setLastModifiedTime" , "createDirectory" ),
167
- "java.util.prefs.FileSystemPreferences" ,
168
- List .of ("lockFile0" , "unlockFile0" ),
169
- "java.nio.file.Files" ,
170
- List .of ("write" , "writeString" , "newOutputStream" , "writeBytes" , "writeAllBytes" , "writeLines" ),
171
- "java.io.File" ,
172
- List .of ("setWritable" )
173
-
155
+ public static final Map <String , List <String >> methodsWhichCanOverwriteFiles = Map .ofEntries (
156
+ new AbstractMap .SimpleEntry <>("java.io.FileOutputStream" ,
157
+ List .of ("<init>" )),
158
+ new AbstractMap .SimpleEntry <>("java.io.RandomAccessFile" ,
159
+ List .of ("write" , "writeBoolean" , "writeByte" , "writeBytes" , "writeChar" , "writeChars" ,
160
+ "writeDouble" , "writeFloat" , "writeInt" , "writeLong" , "writeShort" )),
161
+ new AbstractMap .SimpleEntry <>("java.io.UnixFileSystem" ,
162
+ List .of ("setLastModifiedTime" , "createFileExclusively" , "delete0" , "createDirectory" )),
163
+ new AbstractMap .SimpleEntry <>("java.io.WinNTFileSystem" ,
164
+ List .of ("createFileExclusively" , "delete" , "setLastModifiedTime" , "createDirectory" )),
165
+ new AbstractMap .SimpleEntry <>("java.io.Win32FileSystem" ,
166
+ List .of ("createFileExclusively" , "delete" , "setLastModifiedTime" , "createDirectory" )),
167
+ new AbstractMap .SimpleEntry <>("java.util.prefs.FileSystemPreferences" ,
168
+ List .of ("lockFile0" , "unlockFile0" )),
169
+ new AbstractMap .SimpleEntry <>("java.nio.file.Files" ,
170
+ List .of ("write" , "writeString" , "newOutputStream" , "writeBytes" , "writeAllBytes" , "writeLines" )),
171
+ new AbstractMap .SimpleEntry <>("java.io.File" ,
172
+ List .of ("setWritable" )),
173
+ new AbstractMap .SimpleEntry <>("sun.nio.ch.FileChannelImpl" ,
174
+ List .of ("write" , "writeFully" , "writeDirect" , "writeFromNativeBuffer" ))
174
175
);
175
176
//</editor-fold>
176
177
@@ -200,11 +201,19 @@ static ElementMatcher<MethodDescription> getMethodsMatcher(
200
201
*/
201
202
public static final Map <String , List <String >> methodsWhichCanDeleteFiles = Map .of (
202
203
"java.io.File" ,
203
- List .of ("delete" , " deleteOnExit" ),
204
+ List .of ("deleteOnExit" ),
204
205
"java.nio.file.Files" ,
205
206
List .of ("delete" , "deleteIfExists" ),
206
207
"sun.nio.fs.UnixFileSystemProvider" ,
207
- List .of ("implDelete" )
208
+ List .of ("implDelete" ),
209
+ "sun.nio.fs.WindowsFileSystemProvider" ,
210
+ List .of ("implDelete" ),
211
+ "java.io.UnixFileSystem" ,
212
+ List .of ("delete" ),
213
+ "java.io.WinNTFileSystem" ,
214
+ List .of ("delete" ),
215
+ "java.io.Win32FileSystem" ,
216
+ List .of ("delete" )
208
217
);
209
218
//</editor-fold>
210
219
0 commit comments