ensure all fields are of valid type.
()
| 1303 | |
| 1304 | /** ensure all fields are of valid type. */ |
| 1305 | private void validateFields() { |
| 1306 | // Try to read the value under the read lock |
| 1307 | cacheStructureLock.readLock().lock(); |
| 1308 | try { |
| 1309 | if (validationMap.containsKey(getClass())) { |
| 1310 | return; // Return because this Structure has already been validated |
| 1311 | } |
| 1312 | } finally { |
| 1313 | cacheStructureLock.readLock().unlock(); |
| 1314 | } |
| 1315 | |
| 1316 | // If not found, perform validation and update the cache under the write lock |
| 1317 | cacheStructureLock.writeLock().lock(); |
| 1318 | try { |
| 1319 | // Double-check if another thread has computed the value before we do (see JavaDoc) |
| 1320 | validationMap.computeIfAbsent(getClass(), (cls) -> { |
| 1321 | for (Field f : getFieldList()) { |
| 1322 | validateField(f.getName(), f.getType()); |
| 1323 | } |
| 1324 | return true; |
| 1325 | }); |
| 1326 | } finally { |
| 1327 | cacheStructureLock.writeLock().unlock(); |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | /** Calculates the size, alignment, and field layout of this structure. |
| 1332 | Also initializes any null-valued Structure or NativeMapped |
no test coverage detected