eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
159 stars 129 forks source link

Empty string "" shouldn't trigger NLS warning #2334

Open mickaelistria opened 6 months ago

mickaelistria commented 6 months ago

Empty string is already internationalized, it should require //$NON-NLS-1$ annotations.

srikanth-sankaran commented 6 months ago

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=414196

mickaelistria commented 6 months ago

Thanks @srikanth-sankaran I'm going to quote the insight from @stephan-herrmann here

This would be trivial to change in CompilationUnitDeclaration in either of recordStringLiteral() or reportNLSProblems().

jukzi commented 6 months ago

1960 matches in platform workspace: image

I guess changing this after so many years would lead to more trouble because of "unneeded annotation" warnings/errors then it helps to prevent false positives.

mickaelistria commented 6 months ago

I think the request is still valid: I just hope empty string wouldn't trigger NLS warning, I don't really need to show a warning if the annotation is used. The reportNLSProblems() method seems to be a relatively easy place where to add a condition of the form

if (Arrays.stream(this.stringLiterals).allMatch(literal -> literal.sourceEnd == literal.sourceStart + 2 /* length of "" */)
     && this.nlsTags.length <= this.stringLiterals.length) {
  return;
}