Skip to content

Commit

Permalink
Use System.lineSeparator() rather than \n (#6599)
Browse files Browse the repository at this point in the history
  • Loading branch information
mernst committed May 20, 2024
1 parent 0ee1a3c commit 8d2f4e5
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 58 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -927,9 +927,10 @@ subprojects {
}
} catch (Exception ex) {
if (ex.getCause() != null && ex.getCause().getCause()!= null) {
String msg = ex.getCause().getLocalizedMessage() + ':\n'
msg += ex.getCause().getCause().getLocalizedMessage() + '\n'
msg += 'Have you installed jtreg?'
String msg = String.join(System.lineSeparator(),
ex.getCause().getLocalizedMessage() + ':',
ex.getCause().getCause().getLocalizedMessage(),
'Have you installed jtreg?')
println msg
}
throw ex
Expand Down
18 changes: 10 additions & 8 deletions checker-qual-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ final checkerQualAndroidPom(publication) {
publication.from components.java
publication.pom {
name = 'Checker Qual Android'
description = 'checker-qual-android contains annotations (type qualifiers) that a programmer\n' +
'writes to specify Java code for type-checking by the Checker Framework.\n' +
'\n' +
'The checker-qual-android artifact is identical to the checker-qual\n' +
'artifact, except that in checker-qual-android annotations have classfile\n' +
'retention. The default Android Gradle plugin retains types annotated with\n' +
'runtime annotations in the main dex, but strips out class-retention\n' +
'annotations.\n'
description =
String.join(System.lineSeparator(),
'checker-qual-android contains annotations (type qualifiers) that a programmer',
'writes to specify Java code for type-checking by the Checker Framework.',
'',
'The checker-qual-android artifact is identical to the checker-qual',
'artifact, except that in checker-qual-android annotations have classfile',
'retention. The default Android Gradle plugin retains types annotated with',
'runtime annotations in the main dex, but strips out class-retention',
'annotations.')
licenses {
license {
name = 'The MIT License'
Expand Down
5 changes: 3 additions & 2 deletions checker-qual/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ final checkerQualPom(publication) {
publication.from components.java
publication.pom {
name = 'Checker Qual'
description = 'checker-qual contains annotations (type qualifiers) that a programmer\n' +
'writes to specify Java code for type-checking by the Checker Framework.\n'
description = String.join(System.lineSeparator(),
'checker-qual contains annotations (type qualifiers) that a programmer' +
'writes to specify Java code for type-checking by the Checker Framework.')
licenses {
license {
name = 'The MIT License'
Expand Down
14 changes: 8 additions & 6 deletions checker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -1042,12 +1042,14 @@ final checkerPom(publication) {
// Don't use publication.from components.java which would publish the skinny jar as checker.jar.
publication.pom {
name = 'Checker Framework'
description = 'The Checker Framework enhances Java\'s type system to\n' +
'make it more powerful and useful. This lets software developers\n' +
'detect and prevent errors in their Java programs.\n' +
'The Checker Framework includes compiler plug-ins ("checkers")\n' +
'that find bugs or verify their absence. It also permits you to\n' +
'write your own compiler plug-ins.'
description =
String.join(System.lineSeparator(),
'The Checker Framework enhances Java\'s type system to',
'make it more powerful and useful. This lets software developers',
'detect and prevent errors in their Java programs.',
'The Checker Framework includes compiler plug-ins ("checkers")',
'that find bugs or verify their absence. It also permits you to',
'write your own compiler plug-ins.')
licenses {
license {
name = 'GNU General Public License, version 2 (GPL2), with the classpath exception'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
required.method.not.called=@MustCall %s may not have been invoked on %s or any of its aliases.\nThe type of object is: %s.\nReason for going out of scope: %s
required.method.not.called=@MustCall %s may not have been invoked on %s or any of its aliases.%nThe type of object is: %s.%nReason for going out of scope: %s
missing.creates.mustcall.for=Method %s re-assigns the non-final, owning field %s.%s, but does not have a corresponding @CreatesMustCallFor annotation.
incompatible.creates.mustcall.for=Method %s re-assigns the non-final, owning field %s.%s, but its @CreatesMustCallFor annotation targets %s.
reset.not.owning=Calling method %s resets the must-call obligations of the expression %s, which is non-owning. Either annotate its declaration with an @Owning annotation, extract it into a local variable, or write a corresponding @CreatesMustCallFor annotation on the method that encloses this statement.
creates.mustcall.for.override.invalid=Method %s cannot override method %s, which defines fewer @CreatesMustCallFor targets.\nfound: %s\nrequired: %s
creates.mustcall.for.override.invalid=Method %s cannot override method %s, which defines fewer @CreatesMustCallFor targets.%nfound: %s%nrequired: %s
creates.mustcall.for.invalid.target=Cannot create a must-call obligation for "%s" since its type %s has no must-call methods.
destructor.exceptional.postcondition=Method %s must resolve the must-call obligations of the owning field %s along all paths, including exceptional paths. On an exceptional path, the @EnsuresCalledMethods annotation was not satisfied.\nFound: %s\nRequired: %s
mustcallalias.out.of.scope=This @MustCallAlias parameter might go out of scope without being assigned into an owning field of this object (if this is a constructor) or returned.\nReason for going out of scope: %s
mustcallalias.method.return.and.param=@MustCallAlias annotations must appear in pairs (one on a return type and one on a parameter type).\nBut %s
owning.override.param=Incompatible ownership for parameter %s.\nfound : no ownership annotation or @NotOwning\nrequired: @Owning\nConsequence: method %s in %s cannot override method %s in %s
owning.override.return=Incompatible ownership for return.\nfound : no ownership annotation or @Owning\nrequired: @NotOwning\nConsequence: method %s in %s cannot override method %s in %s
required.method.not.known=The checker cannot determine the must call methods of %s or any of its aliases, so it could not determine if they were called. Typically, this error indicates that you need to write an @MustCall annotation (often on an unconstrained generic type).\nThe type of object is: %s.\nReason for going out of scope: %s
destructor.exceptional.postcondition=Method %s must resolve the must-call obligations of the owning field %s along all paths, including exceptional paths. On an exceptional path, the @EnsuresCalledMethods annotation was not satisfied.%nFound: %s%nRequired: %s
mustcallalias.out.of.scope=This @MustCallAlias parameter might go out of scope without being assigned into an owning field of this object (if this is a constructor) or returned.%nReason for going out of scope: %s
mustcallalias.method.return.and.param=@MustCallAlias annotations must appear in pairs (one on a return type and one on a parameter type).%nBut %s
owning.override.param=Incompatible ownership for parameter %s.%nfound : no ownership annotation or @NotOwning%nrequired: @Owning%nConsequence: method %s in %s cannot override method %s in %s
owning.override.return=Incompatible ownership for return.%nfound : no ownership annotation or @Owning%nrequired: @NotOwning%nConsequence: method %s in %s cannot override method %s in %s
required.method.not.known=The checker cannot determine the must call methods of %s or any of its aliases, so it could not determine if they were called. Typically, this error indicates that you need to write an @MustCall annotation (often on an unconstrained generic type).%nThe type of object is: %s.%nReason for going out of scope: %s
12 changes: 7 additions & 5 deletions dataflow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,13 @@ final dataflowShadedPom(MavenPublication publication, String shadedPkgName) {
publication.artifactId = "dataflow-${shadedPkgName}"
publication.pom {
name = "Dataflow (${shadedPkgName})"
description = "dataflow-${shadedPkgName} is a dataflow framework based on the javac compiler.\n" +
'\n' +
'It differs from the org.checkerframework:dataflow artifact in two ways.\n' +
"First, the packages in this artifact have been renamed to org.checkerframework.${shadedPkgName}.*.\n" +
'Second, unlike the dataflow artifact, this artifact contains the dependencies it requires.'
description =
String.join(System.lineSeparator(),
"dataflow-${shadedPkgName} is a dataflow framework based on the javac compiler.",
'',
'It differs from the org.checkerframework:dataflow artifact in two ways.',
"First, the packages in this artifact have been renamed to org.checkerframework.${shadedPkgName}.*.",
'Second, unlike the dataflow artifact, this artifact contains the dependencies it requires.')
licenses {
license {
name = 'GNU General Public License, version 2 (GPL2), with the classpath exception'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ protected void addBlock(Block b, Set<Block> visited, Queue<Block> workList) {
* @param bb the block
* @param analysis the current analysis
* @param separator the line separator. Examples: "\\l" for left justification in {@link
* DOTCFGVisualizer} (this is really a terminator, not a separator), "\n" to add a new line in
* {@link StringCFGVisualizer}
* DOTCFGVisualizer} (this is really a terminator, not a separator), "\n" or {@code
* System.lineSeparator()} to add a new line in {@link StringCFGVisualizer}
* @return the String representation of the block
*/
protected String visualizeBlockWithSeparator(
Expand Down Expand Up @@ -296,8 +296,8 @@ protected enum VisualizeWhere {
* @param bb a block
* @param analysis the current analysis
* @param separator the line separator. Examples: "\\l" for left justification in {@link
* DOTCFGVisualizer} (which is actually a line TERMINATOR, not a separator!), "\n" to add a
* new line in {@link StringCFGVisualizer}
* DOTCFGVisualizer} (which is actually a line TERMINATOR, not a separator!), "\n" or {@code
* System.lineSeparator()} to add a new line in {@link StringCFGVisualizer}
* @return the visualization of the transfer input before or after the given block
*/
protected String visualizeBlockTransferInputHelper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public static void writeStringOfCFG(
if (res != null && res.get("stringGraph") != null) {
out.write(res.get("stringGraph").toString());
}
out.write("\n");
out.write(System.lineSeparator());
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void init(Map<String, Object> args) {

@Override
public String getSeparator() {
return "\n";
return System.lineSeparator();
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions framework-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ final frameworkTest(publication) {
publication.from components.java
publication.pom {
name = 'Checker Framework Testing Library'
description = 'framework-test contains utility classes for testing type-checkers\n' +
'that are built on the Checker Framework.'
description = String.join(System.lineSeparator(),
'framework-test contains utility classes for testing type-checkers' +
'that are built on the Checker Framework.')
licenses {
license {
name = 'GNU General Public License, version 2 (GPL2), with the classpath exception'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,9 @@ protected void testAnnotationInsertion() {

String withAnnotations;
try (InputStream annotationInputStream = root.getSourceFile().openInputStream()) {
// This check only runs on files from the Checker Framework test suite, which should all
// use UNIX line separators. Using System.lineSeparator instead of "\n" could cause the
// test to fail on Mac or Windows.
withAnnotations =
new InsertAjavaAnnotations(elements)
.insertAnnotations(annotationInputStream, withoutAnnotations, "\n");
.insertAnnotations(annotationInputStream, withoutAnnotations, System.lineSeparator());
} catch (IOException e) {
throw new BugInCF("Error while reading Java file: " + root.getSourceFile().toUri(), e);
}
Expand All @@ -501,7 +498,7 @@ protected void testAnnotationInsertion() {
try {
modifiedAst = JavaParserUtil.parseCompilationUnit(withAnnotations);
} catch (ParseProblemException e) {
throw new BugInCF("Failed to parse code after annotation insertion:\n" + withAnnotations, e);
throw new BugInCF("Failed to parse code after annotation insertion: " + withAnnotations, e);
}

AnnotationEqualityVisitor visitor = new AnnotationEqualityVisitor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private void updateInferredExecutableParameterTypes(
if (showWpiFailedInferences) {
printFailedInferenceDebugMessage(
"Annotations cannot be placed on varargs parameters in -Ainfer=jaifs mode, because"
+ " the JAIF format does not correctly support it.\n"
+ " the JAIF format does not correctly support it. "
+ "The signature of the method whose varargs parameter was not annotated is: "
+ JVMNames.getJVMMethodSignature(methodElt));
}
Expand Down Expand Up @@ -363,7 +363,7 @@ private void updateInferredExecutableParameterTypes(
printFailedInferenceDebugMessage(
"Javac cannot create an array type "
+ "from a wildcard, so WPI did not attempt to infer a type for an array "
+ "parameter.\n"
+ "parameter. "
+ "The signature of the method whose parameter had inference skipped is: "
+ JVMNames.getJVMMethodSignature(methodElt));
}
Expand Down Expand Up @@ -594,7 +594,7 @@ public void updateFromFormalParameterAssignment(
printFailedInferenceDebugMessage(
"Could not update from formal parameter "
+ "assignment, because an ArrayCreationNode with a null tree is created when "
+ "the parameter is a variable-length list.\nParameter: "
+ "the parameter is a variable-length list. Parameter: "
+ paramElt);
}
return;
Expand All @@ -613,7 +613,7 @@ public void updateFromFormalParameterAssignment(
printFailedInferenceDebugMessage(
"Could not update from formal "
+ "parameter assignment inside a lambda expression, because lambda parameters "
+ "cannot be annotated.\nParameter: "
+ "cannot be annotated. Parameter: "
+ paramElt);
}
return;
Expand Down Expand Up @@ -1101,12 +1101,12 @@ public void updateAtmWithLub(AnnotatedTypeMirror sourceCodeATM, AnnotatedTypeMir
} else {
if (showWpiFailedInferences) {
printFailedInferenceDebugMessage(
"attempted to update the component type of an array type, but found an unexpected"
+ " difference in type structure.\n"
+ "LHS kind: "
+ sourceCodeComponent.getKind()
+ "\nRHS kind: "
+ ajavaComponent.getKind());
String.join(
System.lineSeparator(),
"attempted to update the component type of an array type, but found an"
+ " unexpected difference in type structure.",
"LHS kind: " + sourceCodeComponent.getKind(),
"RHS kind: " + ajavaComponent.getKind()));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1316,9 +1316,9 @@ protected void printOrStoreMessage(
*/
private void printStackTrace(StackTraceElement[] trace) {
if (hasOption("dumpOnErrors")) {
StringBuilder msg = new StringBuilder();
StringJoiner msg = new StringJoiner(System.lineSeparator());
for (StackTraceElement elem : trace) {
msg.append("\tat " + elem + "\n");
msg.add("\tat " + elem);
}
message(Diagnostic.Kind.NOTE, msg.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public InferenceFactory(Java8InferenceContext context) {
return new ProperType(res, TreeUtils.typeOf(var), this.context);
} else {
throw new BugInCF(
"Unexpected assignment context.\nKind: %s\nTree: %s", context.getKind(), context);
"Unexpected assignment context.%nKind: %s%nTree: %s", context.getKind(), context);
}
}
}
Expand Down

0 comments on commit 8d2f4e5

Please sign in to comment.