Skip to content

Commit e6da46b

Browse files
committed
1.write SAME_BYTES to cacheMap when wovenbytes is null 2.fix TODO in SimpleCache#getAndInitialize, use Optional to help indicating case in which Hit cache but need to return null Signed-off-by: KimmingLau <[email protected]>
1 parent 1dd77e0 commit e6da46b

File tree

2 files changed

+12
-13
lines changed
  • loadtime/src/main/java/org/aspectj/weaver/loadtime
  • weaver/src/main/java/org/aspectj/weaver/tools/cache

2 files changed

+12
-13
lines changed

loadtime/src/main/java/org/aspectj/weaver/loadtime/Aj.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.HashMap;
2121
import java.util.List;
2222
import java.util.Map;
23+
import java.util.Optional;
2324
import java.util.Set;
2425
import java.util.StringTokenizer;
2526

@@ -104,9 +105,9 @@ public byte[] preProcess(String className, final byte[] bytes, ClassLoader class
104105
synchronized (classLoader) {
105106

106107
if (SimpleCacheFactory.isEnabled()) {
107-
byte[] cacheBytes= laCache.getAndInitialize(className, bytes, classLoader, protectionDomain);
108-
if (cacheBytes!=null){
109-
return cacheBytes;
108+
Optional<byte[]> cacheBytes = laCache.getAndInitialize(className, bytes, classLoader, protectionDomain);
109+
if (cacheBytes != null){
110+
return cacheBytes.orElse(null);
110111
}
111112
}
112113

weaver/src/main/java/org/aspectj/weaver/tools/cache/SimpleCache.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.Collections;
1616
import java.util.HashMap;
1717
import java.util.Map;
18+
import java.util.Optional;
1819
import java.util.zip.CRC32;
1920

2021
import org.aspectj.weaver.Dump;
@@ -64,23 +65,20 @@ protected SimpleCache(String folder, boolean enabled) {
6465
}
6566
}
6667

67-
public byte[] getAndInitialize(String classname, byte[] bytes,
68+
public Optional<byte[]> getAndInitialize(String classname, byte[] bytes,
6869
ClassLoader loader, ProtectionDomain protectionDomain) {
6970
if (!enabled) {
7071
return null;
7172
}
7273
byte[] res = get(classname, bytes);
7374

7475
if (Arrays.equals(SAME_BYTES, res)) {
75-
// TODO: Should we return null (means "not transformed") in this case?
76-
return bytes;
77-
} else {
78-
if (res != null) {
79-
initializeClass(classname, res, loader, protectionDomain);
80-
}
81-
return res;
76+
return Optional.empty();
77+
} else if (res != null) {
78+
initializeClass(classname, res, loader, protectionDomain);
79+
return Optional.of(res);
8280
}
83-
81+
return null;
8482
}
8583

8684
private byte[] get(String classname, byte bytes[]) {
@@ -97,7 +95,7 @@ public void put(String classname, byte[] origbytes, byte[] wovenbytes) {
9795

9896
String key = generateKey(classname, origbytes);
9997

100-
if (Arrays.equals(origbytes, wovenbytes)) {
98+
if (wovenbytes == null || Arrays.equals(origbytes, wovenbytes)) {
10199
cacheMap.put(key, SAME_BYTES);
102100
return;
103101
}

0 commit comments

Comments
 (0)