/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6964768 6964461 6964469 6964487 6964460 6964481 6980021
* @summary need test program to validate javac resource bundles
*/
/**
* Compare string constants in javac classes against keys in javac resource bundles.
*/
public class CheckResourceKeys {
/**
* Main program.
* Options:
* -finddeadkeys
* look for keys in resource bundles that are no longer required
* -findmissingkeys
* look for keys in resource bundles that are missing
*
* @throws Exception if invoked by jtreg and errors occur
*/
CheckResourceKeys c = new CheckResourceKeys();
return;
if (is_jtreg())
else
}
static boolean is_jtreg() {
}
/**
* Main entry point.
*/
boolean findDeadKeys = false;
boolean findMissingKeys = false;
if (is_jtreg()) {
findDeadKeys = true;
findMissingKeys = true;
} else {
System.err.println(" -findmissingkeys find keys in resource bundles that are required but missing");
return true;
}
} else {
findDeadKeys = true;
findMissingKeys = true;
else
}
}
if (errors > 0)
return false;
if (findDeadKeys)
if (findMissingKeys)
return (errors == 0);
}
/**
* Find keys in resource bundles which are probably no longer required.
* A key is probably required if there is a string fragment in the code
* that is part of the resource key, or if the key is well-known
* according to various pragmatic rules.
*/
"compiler.err.", "compiler.warn.", "compiler.note.", "compiler.misc.",
"javac."
};
// some keys are used directly, without a prefix.
continue;
// remove standard prefix
}
}
if (s == null) {
continue;
}
if (codeStrings.contains(s))
continue;
// keys ending in .1 are often synthesized
continue;
// verbose keys are generated by ClassReader.printVerbose
continue;
// mandatory warning messages are synthesized with no characteristic substring
if (isMandatoryWarningString(s))
continue;
// check known (valid) exceptions
continue;
// check known suspects
continue;
}
}
/**
* The keys for mandatory warning messages are all synthesized and do not
* have a significant recognizable substring to look for.
*/
String[] tails = { ".filename", ".filename.additional", ".plural", ".plural.additional", ".recompile" };
if (s.startsWith(b)) {
return true;
}
}
}
return false;
}
// See Resolve.getErrorKey
"compiler.err.cant.resolve.args",
"compiler.err.cant.resolve.args.params",
"compiler.err.cant.resolve.location.args",
"compiler.err.cant.resolve.location.args.params",
// JavaCompiler, reports #errors and #warnings
"compiler.misc.count.error",
"compiler.misc.count.error.plural",
"compiler.misc.count.warn",
"compiler.misc.count.warn.plural",
// Used for LintCategory
"compiler.warn.lintOption",
// Other
"compiler.misc.base.membership" // (sic)
));
"compiler.err.cant.read.file", // UNUSED
"compiler.err.illegal.self.ref", // UNUSED
"compiler.err.io.exception", // UNUSED
"compiler.err.limit.pool.in.class", // UNUSED
"compiler.err.name.reserved.for.internal.use", // UNUSED
"compiler.err.no.match.entry", // UNUSED
"compiler.err.not.within.bounds.explain", // UNUSED
"compiler.err.signature.doesnt.match.intf", // UNUSED
"compiler.err.signature.doesnt.match.supertype", // UNUSED
"compiler.err.type.var.more.than.once", // UNUSED
"compiler.err.type.var.more.than.once.in.result", // UNUSED
"compiler.misc.ccf.found.later.version", // UNUSED
"compiler.misc.non.denotable.type", // UNUSED
"compiler.misc.unnamed.package", // should be required, CR 6964147
"compiler.misc.verbose.retro", // UNUSED
"compiler.misc.verbose.retro.with", // UNUSED
"compiler.misc.verbose.retro.with.list", // UNUSED
"compiler.warn.proc.type.already.exists", // TODO in JavacFiler
"javac.err.invalid.arg", // UNUSED ??
"javac.opt.arg.class", // UNUSED ??
"javac.opt.arg.pathname", // UNUSED ??
"javac.opt.moreinfo", // option commented out
"javac.opt.nogj", // UNUSED
"javac.opt.printflat", // option commented out
"javac.opt.printsearch", // option commented out
"javac.opt.prompt", // option commented out
"javac.opt.retrofit", // UNUSED
"javac.opt.s", // option commented out
"javac.opt.scramble", // option commented out
"javac.opt.scrambleall" // option commented out
));
/**
* For all strings in the code that look like they might be fragments of
* a resource key, verify that a key exists.
*/
// ignore filenames (i.e. in SourceFile attribute
continue;
// ignore package and class names
continue;
// explicit known exceptions
continue;
// look for matching resource
continue;
}
}
}
// where
// system properties
"application.home", // in Paths.java
"env.class.path",
"line.separator",
"user.dir",
// file names
"ct.sym",
"rt.jar",
"tools.jar",
// -XD option names
"process.packages",
"ignore.symbol.file",
"compiler.",
"compiler.misc.",
"count.",
"illegal.",
"javac.",
"verbose."
));
/**
* Look for a resource that ends in this string fragment.
*/
return true;
}
return false;
}
/**
* Get the set of strings from (most of) the javac classfiles.
*/
"javax.annotation.processing",
"javax.lang.model",
"javax.tools",
"com.sun.source",
};
// ignore resource files, and files which are not really part of javac
continue;
}
}
return results;
}
// depending on how the test is run, javac may be on bootclasspath or classpath
try {
return l;
}
} catch (IOException e) {
throw new Error(e);
}
throw new IllegalStateException("Cannot find javac");
}
/**
* Get the set of strings from a class file.
* Only strings that look like they might be a resource key are returned.
*/
try {
if (v.matches("[A-Za-z0-9-_.]+"))
}
}
} catch (ConstantPoolException ignore) {
} finally {
}
}
/**
* Get the set of keys from the javac resource bundles.
*/
ResourceBundle b =
}
return results;
}
/**
* Report an error.
*/
errors++;
}
int errors;
}