Skip to content

Commit 80d9f68

Browse files
committed
Use %n in some error messages
1 parent c0ea644 commit 80d9f68

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageHeap.java

+18-21
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,12 @@ public void addObject(final Object original, boolean immutableFromParent, final
246246
* not seen - so this check actually protects against much more than just missing class
247247
* initialization information.
248248
*/
249-
throw VMError.shouldNotReachHere("Image heap writing found a class not seen as instantiated during static analysis. " +
250-
"Did a static field or an object referenced from a static field change during native image generation? " +
251-
"For example, a lazily initialized cache could have been initialized during image generation, " +
252-
"in which case you need to force eager initialization of the cache before static analysis or reset the cache using a field value recomputation.\n" +
253-
" class: " + original + "\n" +
254-
" reachable through:\n" +
255-
fillReasonStack(new StringBuilder(), reason));
249+
throw VMError.shouldNotReachHere(String.format(
250+
"Image heap writing found a class not seen as instantiated during static analysis. Did a static field or an object referenced " +
251+
"from a static field change during native image generation? For example, a lazily initialized cache could have been " +
252+
"initialized during image generation, in which case you need to force eager initialization of the cache before static analysis " +
253+
"or reset the cache using a field value recomputation.%n class: %s%n reachable through:%n%s",
254+
original, fillReasonStack(new StringBuilder(), reason)));
256255
}
257256

258257
int identityHashCode;
@@ -344,13 +343,13 @@ private void addObjectToBootImageHeap(final Object object, boolean immutableFrom
344343

345344
final Optional<HostedType> optionalType = getMetaAccess().optionalLookupJavaType(object.getClass());
346345
if (!optionalType.isPresent() || !optionalType.get().isInstantiated()) {
347-
throw UserError.abort("Image heap writing found an object whose class was not seen as instantiated during static analysis. " +
348-
"Did a static field or an object referenced from a static field change during native image generation? " +
349-
"For example, a lazily initialized cache could have been initialized during image generation, " +
350-
"in which case you need to force eager initialization of the cache before static analysis or reset the cache using a field value recomputation.\n" +
351-
" object: " + object + " of class: " + object.getClass().getTypeName() + "\n" +
352-
" reachable through:\n" +
353-
fillReasonStack(new StringBuilder(), reason));
346+
throw UserError.abort(
347+
String.format("Image heap writing found an object whose class was not seen as instantiated during static analysis. " +
348+
"Did a static field or an object referenced from a static field change during native image generation? " +
349+
"For example, a lazily initialized cache could have been initialized during image generation, in which case " +
350+
"you need to force eager initialization of the cache before static analysis or reset the cache using a field " +
351+
"value recomputation.%n object: %s of class: %s%n reachable through:%n%s",
352+
object, object.getClass().getTypeName(), fillReasonStack(new StringBuilder(), reason)));
354353
}
355354
final HostedType type = optionalType.get();
356355
final DynamicHub hub = type.getHub();
@@ -558,20 +557,18 @@ private void mustBeReferenceAligned(int index) {
558557

559558
private static void verifyTargetDidNotChange(Object target, Object reason, Object targetInfo) {
560559
if (targetInfo == null) {
561-
throw UserError.abort("Static field or an object referenced from a static field changed during native image generation?\n" +
562-
" object:" + target + " of class: " + target.getClass().getTypeName() + "\n" +
563-
" reachable through:\n" +
564-
fillReasonStack(new StringBuilder(), reason));
560+
throw UserError.abort(String.format("Static field or an object referenced from a static field changed during native image generation?%n" +
561+
" object:%s of class: %s%n reachable through:%n%s", target, target.getClass().getTypeName(), fillReasonStack(new StringBuilder(), reason)));
565562
}
566563
}
567564

568565
private static StringBuilder fillReasonStack(StringBuilder msg, Object reason) {
569566
if (reason instanceof ObjectInfo) {
570567
ObjectInfo info = (ObjectInfo) reason;
571-
msg.append(" object: ").append(info.getObject()).append(" of class: ").append(info.getObject().getClass().getTypeName()).append("\n");
568+
msg.append(" object: ").append(info.getObject()).append(" of class: ").append(info.getObject().getClass().getTypeName()).append(System.lineSeparator());
572569
return fillReasonStack(msg, info.reason);
573570
}
574-
return msg.append(" root: ").append(reason).append("\n");
571+
return msg.append(" root: ").append(reason).append(System.lineSeparator());
575572
}
576573

577574
private void writeField(RelocatableBuffer buffer, ObjectInfo fields, HostedField field, JavaConstant receiver, ObjectInfo info) {
@@ -1198,7 +1195,7 @@ void printHistogram() {
11981195
}
11991196

12001197
void printSize() {
1201-
System.out.printf("PrintImageHeapPartitionSizes: partition: %s size: %d\n", name, getSize());
1198+
System.out.printf("PrintImageHeapPartitionSizes: partition: %s size: %d%n", name, getSize());
12021199
}
12031200

12041201
private HeapPartition(String name, NativeImageHeap heap, boolean writable) {

0 commit comments

Comments
 (0)