Skip to content

Commit 5a42780

Browse files
authored
rename StaticLinkageError (GoogleCloudPlatform#451)
* rename StaticLinkageError * SymbolNotResolvable
1 parent bed7816 commit 5a42780

9 files changed

Lines changed: 115 additions & 111 deletions

File tree

‎dependencies/src/main/java/com/google/cloud/tools/opensource/classpath/ClasspathChecker.java‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import org.apache.bcel.classfile.Method;
4141

4242
/**
43-
* A tool to find static linkage errors for a class path.
43+
* A tool to find linkage errors in a class path.
4444
*/
4545
public class ClasspathChecker {
4646

@@ -130,11 +130,11 @@ JarLinkageReport generateLinkageReport(
130130
}
131131

132132
private static <R extends SymbolReference>
133-
ImmutableList<StaticLinkageError<R>> errorsFromSymbolReferences(
133+
ImmutableList<SymbolNotResolvable<R>> errorsFromSymbolReferences(
134134
Set<R> symbolReferences,
135135
Set<String> classesDefinedInJar,
136-
Function<R, Optional<StaticLinkageError<R>>> checkFunction) {
137-
ImmutableList<StaticLinkageError<R>> linkageErrors =
136+
Function<R, Optional<SymbolNotResolvable<R>>> checkFunction) {
137+
ImmutableList<SymbolNotResolvable<R>> linkageErrors =
138138
symbolReferences.stream()
139139
.filter(reference -> !classesDefinedInJar.contains(reference.getTargetClassName()))
140140
.map(checkFunction)
@@ -155,7 +155,7 @@ ImmutableList<StaticLinkageError<R>> errorsFromSymbolReferences(
155155
* Virtual Machine Specification: 5.4.3.4. Interface Method Resolution</a>
156156
*/
157157
@VisibleForTesting
158-
Optional<StaticLinkageError<MethodSymbolReference>> checkLinkageErrorMissingMethodAt(
158+
Optional<SymbolNotResolvable<MethodSymbolReference>> checkLinkageErrorMissingMethodAt(
159159
MethodSymbolReference reference) {
160160
String targetClassName = reference.getTargetClassName();
161161
String sourceClassName = reference.getSourceClassName();
@@ -172,13 +172,13 @@ Optional<StaticLinkageError<MethodSymbolReference>> checkLinkageErrorMissingMeth
172172
Path classFileLocation = classDumper.findClassLocation(targetClassName);
173173
if (!isClassAccessibleFrom(targetJavaClass, sourceClassName)) {
174174
return Optional.of(
175-
StaticLinkageError.errorInaccessibleClass(
175+
SymbolNotResolvable.errorInaccessibleClass(
176176
reference, classFileLocation, isSourceClassReachable));
177177
}
178178

179179
if (targetJavaClass.isInterface() != reference.isInterfaceMethod()) {
180180
return Optional.of(
181-
StaticLinkageError.errorIncompatibleClassChange(
181+
SymbolNotResolvable.errorIncompatibleClassChange(
182182
reference, classFileLocation, isSourceClassReachable));
183183
}
184184

@@ -197,7 +197,7 @@ Optional<StaticLinkageError<MethodSymbolReference>> checkLinkageErrorMissingMeth
197197
&& method.getSignature().equals(reference.getDescriptor())) {
198198
if (!isMemberAccessibleFrom(javaClass, method, sourceClassName)) {
199199
return Optional.of(
200-
StaticLinkageError.errorInaccessibleMember(
200+
SymbolNotResolvable.errorInaccessibleMember(
201201
reference, classFileLocation, isSourceClassReachable));
202202
}
203203
// The method is found and accessible. Returning no error.
@@ -208,14 +208,14 @@ Optional<StaticLinkageError<MethodSymbolReference>> checkLinkageErrorMissingMeth
208208

209209
// The class is in class path but the symbol is not found
210210
return Optional.of(
211-
StaticLinkageError.errorMissingMember(
211+
SymbolNotResolvable.errorMissingMember(
212212
reference, classFileLocation, isSourceClassReachable));
213213
} catch (ClassNotFoundException ex) {
214214
if (classDumper.catchesNoClassDefFoundError(reference)) {
215215
return Optional.empty();
216216
}
217217
return Optional.of(
218-
StaticLinkageError.errorMissingTargetClass(reference, isSourceClassReachable));
218+
SymbolNotResolvable.errorMissingTargetClass(reference, isSourceClassReachable));
219219
}
220220
}
221221

@@ -225,7 +225,7 @@ Optional<StaticLinkageError<MethodSymbolReference>> checkLinkageErrorMissingMeth
225225
* Optional}.
226226
*/
227227
@VisibleForTesting
228-
Optional<StaticLinkageError<FieldSymbolReference>> checkLinkageErrorMissingFieldAt(
228+
Optional<SymbolNotResolvable<FieldSymbolReference>> checkLinkageErrorMissingFieldAt(
229229
FieldSymbolReference reference) {
230230
String targetClassName = reference.getTargetClassName();
231231
String sourceClassName = reference.getSourceClassName();
@@ -236,7 +236,7 @@ Optional<StaticLinkageError<FieldSymbolReference>> checkLinkageErrorMissingField
236236
Path classFileLocation = classDumper.findClassLocation(targetClassName);
237237
if (!isClassAccessibleFrom(targetJavaClass, sourceClassName)) {
238238
return Optional.of(
239-
StaticLinkageError.errorInaccessibleClass(
239+
SymbolNotResolvable.errorInaccessibleClass(
240240
reference, classFileLocation, isSourceClassReachable));
241241
}
242242

@@ -245,7 +245,7 @@ Optional<StaticLinkageError<FieldSymbolReference>> checkLinkageErrorMissingField
245245
if (field.getName().equals(fieldName)) {
246246
if (!isMemberAccessibleFrom(javaClass, field, sourceClassName)) {
247247
return Optional.of(
248-
StaticLinkageError.errorInaccessibleMember(
248+
SymbolNotResolvable.errorInaccessibleMember(
249249
reference, classFileLocation, isSourceClassReachable));
250250
}
251251
// The field is found and accessible. Returning no error.
@@ -255,14 +255,14 @@ Optional<StaticLinkageError<FieldSymbolReference>> checkLinkageErrorMissingField
255255
}
256256
// The field was not found in the class from the classpath
257257
return Optional.of(
258-
StaticLinkageError.errorMissingMember(
258+
SymbolNotResolvable.errorMissingMember(
259259
reference, classFileLocation, isSourceClassReachable));
260260
} catch (ClassNotFoundException ex) {
261261
if (classDumper.catchesNoClassDefFoundError(reference)) {
262262
return Optional.empty();
263263
}
264264
return Optional.of(
265-
StaticLinkageError.errorMissingTargetClass(reference, isSourceClassReachable));
265+
SymbolNotResolvable.errorMissingTargetClass(reference, isSourceClassReachable));
266266
}
267267
}
268268

@@ -315,7 +315,7 @@ private boolean isMemberAccessibleFrom(
315315
* Optional}.
316316
*/
317317
@VisibleForTesting
318-
Optional<StaticLinkageError<ClassSymbolReference>> checkLinkageErrorMissingClassAt(
318+
Optional<SymbolNotResolvable<ClassSymbolReference>> checkLinkageErrorMissingClassAt(
319319
ClassSymbolReference reference) {
320320
String sourceClassName = reference.getSourceClassName();
321321
String targetClassName = reference.getTargetClassName();
@@ -328,13 +328,13 @@ Optional<StaticLinkageError<ClassSymbolReference>> checkLinkageErrorMissingClass
328328
&& !classDumper.hasValidSuperclass(
329329
classDumper.loadJavaClass(sourceClassName), targetClass)) {
330330
return Optional.of(
331-
StaticLinkageError.errorIncompatibleClassChange(
331+
SymbolNotResolvable.errorIncompatibleClassChange(
332332
reference, classFileLocation, isSourceClassReachable));
333333
}
334334

335335
if (!isClassAccessibleFrom(targetClass, sourceClassName)) {
336336
return Optional.of(
337-
StaticLinkageError.errorInaccessibleClass(
337+
SymbolNotResolvable.errorInaccessibleClass(
338338
reference, classFileLocation, isSourceClassReachable));
339339
}
340340
return Optional.empty();
@@ -345,7 +345,7 @@ Optional<StaticLinkageError<ClassSymbolReference>> checkLinkageErrorMissingClass
345345
return Optional.empty();
346346
}
347347
return Optional.of(
348-
StaticLinkageError.errorMissingTargetClass(reference, isSourceClassReachable));
348+
SymbolNotResolvable.errorMissingTargetClass(reference, isSourceClassReachable));
349349
}
350350
}
351351

‎dependencies/src/main/java/com/google/cloud/tools/opensource/classpath/JarLinkageReport.java‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public abstract class JarLinkageReport {
4040
*/
4141
public abstract Path getJarPath();
4242

43-
public abstract ImmutableList<StaticLinkageError<ClassSymbolReference>> getMissingClassErrors();
43+
public abstract ImmutableList<SymbolNotResolvable<ClassSymbolReference>> getMissingClassErrors();
4444

45-
public abstract ImmutableList<StaticLinkageError<MethodSymbolReference>> getMissingMethodErrors();
45+
public abstract ImmutableList<SymbolNotResolvable<MethodSymbolReference>> getMissingMethodErrors();
4646

47-
public abstract ImmutableList<StaticLinkageError<FieldSymbolReference>> getMissingFieldErrors();
47+
public abstract ImmutableList<SymbolNotResolvable<FieldSymbolReference>> getMissingFieldErrors();
4848

4949
static Builder builder() {
5050
return new AutoValue_JarLinkageReport.Builder();
@@ -55,13 +55,13 @@ abstract static class Builder {
5555
abstract Builder setJarPath(Path value);
5656

5757
abstract Builder setMissingClassErrors(
58-
Iterable<StaticLinkageError<ClassSymbolReference>> errors);
58+
Iterable<SymbolNotResolvable<ClassSymbolReference>> errors);
5959

6060
abstract Builder setMissingMethodErrors(
61-
Iterable<StaticLinkageError<MethodSymbolReference>> errors);
61+
Iterable<SymbolNotResolvable<MethodSymbolReference>> errors);
6262

6363
abstract Builder setMissingFieldErrors(
64-
Iterable<StaticLinkageError<FieldSymbolReference>> errors);
64+
Iterable<SymbolNotResolvable<FieldSymbolReference>> errors);
6565

6666
abstract JarLinkageReport build();
6767
}
@@ -73,15 +73,15 @@ public String toString() {
7373
int totalErrors = getCauseToSourceClassesSize();
7474

7575
builder.append(getJarPath().getFileName() + " (" + totalErrors + " errors):\n");
76-
for (StaticLinkageError<ClassSymbolReference> missingClass : getMissingClassErrors()) {
76+
for (SymbolNotResolvable<ClassSymbolReference> missingClass : getMissingClassErrors()) {
7777
builder.append(indent + missingClass);
7878
builder.append("\n");
7979
}
80-
for (StaticLinkageError<MethodSymbolReference> missingMethod : getMissingMethodErrors()) {
80+
for (SymbolNotResolvable<MethodSymbolReference> missingMethod : getMissingMethodErrors()) {
8181
builder.append(indent + missingMethod);
8282
builder.append("\n");
8383
}
84-
for (StaticLinkageError<FieldSymbolReference> missingField : getMissingFieldErrors()) {
84+
for (SymbolNotResolvable<FieldSymbolReference> missingField : getMissingFieldErrors()) {
8585
builder.append(indent + missingField);
8686
builder.append("\n");
8787
}
@@ -90,13 +90,13 @@ public String toString() {
9090

9191
/** Returns map from the cause of linkage errors to class names affected by the errors. */
9292
public ImmutableMultimap<LinkageErrorCause, String> getCauseToSourceClasses() {
93-
ImmutableListMultimap<LinkageErrorCause, StaticLinkageError<ClassSymbolReference>>
93+
ImmutableListMultimap<LinkageErrorCause, SymbolNotResolvable<ClassSymbolReference>>
9494
groupedClassErrors = Multimaps.index(getMissingClassErrors(), LinkageErrorCause::from);
9595

96-
ImmutableListMultimap<LinkageErrorCause, StaticLinkageError<MethodSymbolReference>>
96+
ImmutableListMultimap<LinkageErrorCause, SymbolNotResolvable<MethodSymbolReference>>
9797
groupedMethodErrors = Multimaps.index(getMissingMethodErrors(), LinkageErrorCause::from);
9898

99-
ImmutableListMultimap<LinkageErrorCause, StaticLinkageError<FieldSymbolReference>>
99+
ImmutableListMultimap<LinkageErrorCause, SymbolNotResolvable<FieldSymbolReference>>
100100
groupedFieldErrors = Multimaps.index(getMissingFieldErrors(), LinkageErrorCause::from);
101101

102102
// ImmutableSet ensures deterministic iteration order
@@ -109,7 +109,7 @@ public ImmutableMultimap<LinkageErrorCause, String> getCauseToSourceClasses() {
109109

110110
ImmutableMultimap.Builder<LinkageErrorCause, String> builder = ImmutableMultimap.builder();
111111
for (LinkageErrorCause key : combinedKeys) {
112-
List<StaticLinkageError<? extends SymbolReference>> allErrorsForKey =
112+
List<SymbolNotResolvable<? extends SymbolReference>> allErrorsForKey =
113113
Lists.newArrayList(
114114
Iterables.concat(
115115
groupedClassErrors.get(key),
@@ -118,7 +118,7 @@ public ImmutableMultimap<LinkageErrorCause, String> getCauseToSourceClasses() {
118118
builder.putAll(
119119
key,
120120
allErrorsForKey.stream()
121-
.map(StaticLinkageError::getReference)
121+
.map(SymbolNotResolvable::getReference)
122122
.map(SymbolReference::getSourceClassName)
123123
.map(className -> className.split("\\$")[0]) // Removing duplicate inner classes
124124
.collect(toImmutableSet()));

‎dependencies/src/main/java/com/google/cloud/tools/opensource/classpath/LinkageErrorCause.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
2323
abstract class LinkageErrorCause {
2424

2525
/** Returns the reason for the error */
26-
abstract StaticLinkageError.Reason getReason();
26+
abstract SymbolNotResolvable.Reason getReason();
2727

2828
/** Returns the symbol causing the error. It's either class name, field name, or method name. */
2929
abstract String getSymbol();
3030

3131
static <T extends SymbolReference> LinkageErrorCause from(
32-
StaticLinkageError<T> staticLinkageError) {
32+
SymbolNotResolvable<T> staticLinkageError) {
3333
String symbolName = symbolNameFrom(staticLinkageError);
3434
return new AutoValue_LinkageErrorCause(staticLinkageError.getReason(), symbolName);
3535
}
3636

3737
private static <T extends SymbolReference> String symbolNameFrom(
38-
StaticLinkageError<T> staticLinkageError) {
38+
SymbolNotResolvable<T> staticLinkageError) {
3939
T reference = staticLinkageError.getReference();
4040
switch (staticLinkageError.getReason()) {
4141
case INACCESSIBLE_MEMBER:

dependencies/src/main/java/com/google/cloud/tools/opensource/classpath/StaticLinkageError.java renamed to dependencies/src/main/java/com/google/cloud/tools/opensource/classpath/SymbolNotResolvable.java

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,23 @@
2121
import javax.annotation.Nullable;
2222

2323
/**
24-
* Static linkage error caused by a symbol reference.
24+
* Linkage error caused by a symbol reference that cannot be resolved.
2525
*
26-
* @param <T> type of symbol reference that caused the linkage error
26+
* @param <T> symbol reference that caused the linkage error
2727
* @see <a
28-
* href="https://github.com/GoogleCloudPlatform/cloud-opensource-java/blob/master/library-best-practices/glossary.md#static-linkage-error">
29-
* Java Dependency Glossary: Static linkage error</a>
28+
* href="https://github.com/GoogleCloudPlatform/cloud-opensource-java/blob/master/library-best-practices/glossary.md#linkage-error">
29+
* Java Dependency Glossary: Linkage Error</a>
3030
*/
3131
@AutoValue
32-
abstract class StaticLinkageError<T extends SymbolReference> {
32+
abstract class SymbolNotResolvable<T extends SymbolReference> {
3333

34-
/** Returns the symbol reference on which this linkage error occurred. */
34+
/** Returns the symbol reference that could not be resolved. */
3535
abstract T getReference();
3636

3737
/**
38-
* Returns the location of the target class in the symbol reference; null if the target class is
39-
* not found in the class path or the source location is unavailable.
38+
* Returns the path to the class where symbol reference was expected to be found.
39+
* This is null if the target class is not found in the class path or the source
40+
* location is unavailable.
4041
*/
4142
@Nullable
4243
abstract Path getTargetClassLocation();
@@ -68,17 +69,17 @@ public String toString() {
6869
return builder.toString();
6970
}
7071

71-
/** Returns a linkage error caused by {@link Reason#CLASS_NOT_FOUND}. */
72-
static <U extends SymbolReference> StaticLinkageError<U> errorMissingTargetClass(
72+
/** Returns a SymbolNotFound caused by {@link Reason#CLASS_NOT_FOUND}. */
73+
static <U extends SymbolReference> SymbolNotResolvable<U> errorMissingTargetClass(
7374
U reference, boolean isReachable) {
7475
return builderFor(reference)
7576
.setReason(Reason.CLASS_NOT_FOUND)
7677
.setReachable(isReachable)
7778
.build();
7879
}
7980

80-
/** Returns a linkage error caused by {@link Reason#INCOMPATIBLE_CLASS_CHANGE}. */
81-
static <U extends SymbolReference> StaticLinkageError<U> errorIncompatibleClassChange(
81+
/** Returns a SymbolNotFound caused by {@link Reason#INCOMPATIBLE_CLASS_CHANGE}. */
82+
static <U extends SymbolReference> SymbolNotResolvable<U> errorIncompatibleClassChange(
8283
U reference, Path targetClassLocation, boolean isReachable) {
8384
return builderFor(reference)
8485
.setReason(Reason.INCOMPATIBLE_CLASS_CHANGE)
@@ -87,8 +88,8 @@ static <U extends SymbolReference> StaticLinkageError<U> errorIncompatibleClassC
8788
.build();
8889
}
8990

90-
/** Returns a linkage error caused by {@link Reason#SYMBOL_NOT_FOUND}. */
91-
static <U extends SymbolReference> StaticLinkageError<U> errorMissingMember(
91+
/** Returns a SymbolNotFound caused by {@link Reason#SYMBOL_NOT_FOUND}. */
92+
static <U extends SymbolReference> SymbolNotResolvable<U> errorMissingMember(
9293
U reference, Path targetClassLocation, boolean isReachable) {
9394
return builderFor(reference)
9495
.setReason(Reason.SYMBOL_NOT_FOUND)
@@ -97,8 +98,8 @@ static <U extends SymbolReference> StaticLinkageError<U> errorMissingMember(
9798
.build();
9899
}
99100

100-
/** Returns a linkage error caused by {@link Reason#INACCESSIBLE_CLASS}. */
101-
static <U extends SymbolReference> StaticLinkageError<U> errorInaccessibleClass(
101+
/** Returns a SymbolNotFound caused by {@link Reason#INACCESSIBLE_CLASS}. */
102+
static <U extends SymbolReference> SymbolNotResolvable<U> errorInaccessibleClass(
102103
U reference, Path targetClassLocation, boolean isReachable) {
103104
return builderFor(reference)
104105
.setReason(Reason.INACCESSIBLE_CLASS)
@@ -107,8 +108,8 @@ static <U extends SymbolReference> StaticLinkageError<U> errorInaccessibleClass(
107108
.build();
108109
}
109110

110-
/** Returns a linkage error caused by {@link Reason#INACCESSIBLE_MEMBER}. */
111-
static <U extends SymbolReference> StaticLinkageError<U> errorInaccessibleMember(
111+
/** Returns a SymbolNotFound caused by {@link Reason#INACCESSIBLE_MEMBER}. */
112+
static <U extends SymbolReference> SymbolNotResolvable<U> errorInaccessibleMember(
112113
U reference, Path targetClassLocation, boolean isReachable) {
113114
return builderFor(reference)
114115
.setReason(Reason.INACCESSIBLE_MEMBER)
@@ -117,29 +118,32 @@ static <U extends SymbolReference> StaticLinkageError<U> errorInaccessibleMember
117118
.build();
118119
}
119120

120-
/** Returns {@code Builder} for a linkage error that occurred at the symbol reference. */
121+
/**
122+
* Returns a {@code SymbolNotFound.Builder} for a linkage error that occurred at the symbol
123+
* reference.
124+
*/
121125
private static <U extends SymbolReference> Builder<U> builderFor(U reference) {
122126
// This method gives type-safety compared with normal builder() method.
123-
Builder<U> builder = new AutoValue_StaticLinkageError.Builder<>();
127+
Builder<U> builder = new AutoValue_SymbolNotResolvable.Builder<>();
124128
builder.setReference(reference);
125129
return builder;
126130
}
127131

128132
@AutoValue.Builder
129133
abstract static class Builder<T extends SymbolReference> {
130134

131-
abstract StaticLinkageError.Builder<T> setTargetClassLocation(Path targetClassLocation);
135+
abstract SymbolNotResolvable.Builder<T> setTargetClassLocation(Path targetClassLocation);
132136

133-
abstract StaticLinkageError.Builder<T> setReason(Reason reason);
137+
abstract SymbolNotResolvable.Builder<T> setReason(Reason reason);
134138

135-
abstract StaticLinkageError.Builder<T> setReference(T reference);
139+
abstract SymbolNotResolvable.Builder<T> setReference(T reference);
136140

137-
abstract StaticLinkageError.Builder<T> setReachable(boolean reachable);
141+
abstract SymbolNotResolvable.Builder<T> setReachable(boolean reachable);
138142

139-
abstract StaticLinkageError<T> build();
143+
abstract SymbolNotResolvable<T> build();
140144
}
141145

142-
/** Reason to distinguish the cause of a static linkage error against a symbol reference. */
146+
/** The kind of linkage error against a symbol reference. */
143147
enum Reason {
144148
/** The target class of the symbol reference is not found in the class path. */
145149
CLASS_NOT_FOUND,

0 commit comments

Comments
 (0)