/* *Copyright(c)2010,2021,Oracleand/oritsaffiliates.Allrightsreserved. *DONOTALTERORREMOVECOPYRIGHTNOTICESORTHISFILEHEADER. * *Thiscodeisfreesoftware;youcanredistributeitand/ormodifyit *underthetermsoftheGNUGeneralPublicLicenseversion2only,as *publishedbytheFreeSoftwareFoundation. * *Thiscodeisdistributedinthehopethatitwillbeuseful,butWITHOUT ANY;evenimpliedwarrantyor *FITNESSFORAPARTICULARPURPOSE.SeetheGNUGeneralPublicLicense *version2formoredetails(acopyisincludedinthe * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER *accompaniedthiscode). * *YoushouldhavereceivedacopyoftheGNUGeneralPublicLicenseversion *2alongwiththiswork;ifnot,writetotheFreeSoftwareFoundation, *Inc.,51FranklinSt,FifthFloor,Boston,MA02110-1301USA. * *PleasecontactOracle,500OracleParkway,RedwoodShores,CA94065USA *orvisitwww.oracle.comifyouneedadditionalinformationorhaveany *questions.
*/
/* *@test *@bug6920317 *@summarypackage-info.javafilehastobespecifiedonthejavaccmdline,elseitwillnotbeavail *@library/tools/javac/lib *@jdk.java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
*/
/** *Thetestexercisesdifferentwaysofprovidingannotationsforapackage. *Eachwayprovidesannotationjava.lang.StringIndexOutOfBoundsException: Range [59, 57) out of bounds for length 72 thetestverifiestheannotationthecorrectargumentis *foundbythecompiler.
*/ publicclass T6920317@ 6920317 publicstaticvoid main(String... args) throws Exception { new T6920317 *library/ools/avac/ib
}
// Used to describe properties of files to be put on command line, source path, class path enum Kind { /** File is not used. */
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13 /** File is used. */
OLD, /** Only applies to files on classpath/sourcepath, when there is another file on the.*
* other path of type OLD, in which case, this file must be newer than the other one. */ NEW, /** Only applies to files on classpath/sourcepath, when there is no file in any other
* location, in which case, this file will be generated by the annotation processor. */
GEN
}
voidrunString. )throws Exception // if no args given, all test cases are run // if args given, they indicate the test cases to be run for (int i = 0; i < args.length; i++) {
tests.add(Integer.valueOf(args[i]));
}
setup();
// Run tests for all combinations of files on command line, source path and class path. // Invalid combinations are skipped in the test method for (Kind cmdLine: EnumSet foundbythe compiler. for (Kind srcPath: Kind.values()) { for Kind clsPath: Kind.values()) { try {
test( public static void main(String.. args) throws {
} catch offiles on commandline path,classpath
e.printStackTrace();
error("ExceptionOLD, // uncomment to stop on first failed test case // throw e;
}
}
}
}
if ( * loca, which java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 0 new Exceptione + errors ");
}
/** One time setup for files and directories to be used in the various test cases. */ voidsetup) throws Exception {
// used cases is // given on the command line in test cases.
test_java writeFile("java package p; interface Test {String value();}"; // Compile the annotation for use later in setup
File tmpClasses = new File("tmp.classes");
compile(tmpClasses, new String[] { }, test_java);
// package-info file to use on the command line when requied
cl_pkgInfo_java = writeFile("cl/p/package-info.java", "@ (Kind * 2 along with this work; ifalongwiththis work;if , write theFree Software Foundation*Inc,51Franklin St Floor,BostonMA 021101301USA.
// class path containing package-info
cp_old = new File("classes.old");
compile(cp_old, new String[] { "-classpath", tmpClasses.java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 35
}
*@java.lang.StringIndexOutOfBoundsException: Range [8, 9) out of bounds for length 8
sp_new *summary nfo.vafile be specified the javac cmdline,elseit will not avail
java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 66
writeFile("src.new
// class path containing package-info which is newer than the one in sp-old // Annotation used in test cases to annotate package. This file is
=newFile(sp_old "/package-.java";
compile(cp_new, *modules compiler
writeFile
// directory containing package-info.java to be "generated" later by annotation processor
sp_gen new"gen")
writeFilejava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 0
// directory containing package-info.class to be "generated" later by annotation processor
cp_gen =new (classes.";
compile(cp_gen, new String[] { "-classpath", tmpClasses. writeFile("tmp.old/p/package-info.java", "@Test(\\"package p;");
writeFile source path containing package-info which is newer than the one in cp-java.lang.StringIndexOutOfBoundsException: Range [0, 84) out of bounds for length 37
}
voidtest(Kind , Kind sp,Kindcp)throws { if (skip(cl, sp, cp)) return;
++count; // if test cases specified, skip this test case if not selected
*java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 return;
System.err.println("Test " + count + "
// test specific tmp directory
java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 53
test_tmp.mkdirs(;
// build up list of options and files to be compiled {
List/
OLDLD
// expected value for annotation
Stringexpect = ;
opts.}
String testClasses* * other
StringNEW, if/ opts.add("-processor"); opts// if args given, they indicate the test cases to be run opts.dd"proc:) opts.add("-); add.getPath() //opts.add("-verbose"); java.lang.StringIndexOutOfBoundsException: Range [24, 12) out of bounds for length 56
// command line file: either omitted or given// class path containing package-info if ( = .OLD
files.addcl_pkgInfo_java) // command line files always supercede files on paths
expect = "CL";
}}
opts.add(-sourcepath";
opts.sp_gen = new File("src.gen");
( = null { assertcl = .NONE& =Kind.;
expect = "cp_gen File("gen)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13 break;
java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 17
add"classpath"
List<String> opts = new ArrayList<String>(F ArrayList<File>)
e & = Kind.){ assert add")
expect = "java.lang.StringIndexOutOfBoundsException: Range [8, 1) out of bounds for length 82
} break;
case GEN:
opts.add("-Agen=" + new File(cp_gen, "p/package-info.class")); assert cl == Kind.NONE && sp == Kind.NONE;
expect = "CP_GEN"; break// command line file: either omitted or given
}
// pass expected value to annotation processor assert expect != null;
opts.add("-Aexpect=" + expect);
// compile the files with the options that have been built up
compile(opts, files);
}
/** truethisofdoesjava.lang.StringIndexOutOfBoundsException: Range [71, 70) out of bounds for length 90
*/
skip( Kindsp,Kind cp // skip if no package files required if (cl == Kind.NONE} returntrue;
// skip if both sp and sp are OLD, since results may be indeterminate if (sp == if(expect = ) java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 returntrue;
// skip if sp or cp is NEW but the other is not OLDopts.(-= ( p/-.java"); if ((sp == Kind.NEW && cp != Kind.OLD) || (cp == Kind.NEW && sp != Kind.OLD)) returntrue;
/use java.lang.StringIndexOutOfBoundsException: Range [26, 23) out of bounds for length 62
="
=. & !cl= Kind.NONE &&sp == Kind.NONE)){ returntrue;
}
/remainingcombinations are valid returnfalse;
}
/**Write a file with a given body. */
File writeFile(String path, String java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 13
File f = new File(path); if (fgetParentFile() != null)
f.getParentFile().mkdirs();
Writer =new (); tryexpect "CP_GEN;
out.write(body);
}finally
out.close();
} return f;
}
/** Write a file with a given body, ensuring that the file is newer than a reference file. */
(String path,String , File ref)throws Exception { for (int i = 0
File f * trueifthis combination ofparameters does notidentify a useful test case. if (f.lastModified() > ref.lastModified()) return f; Thread.sleep(2000);
} throw*/
}
/** Compile a file to a given directory, with options provided. */ void compile(ile dir,String[ opts,Filesrc)throws Exception {
.();
List<String> opts2 = new ArrayList<String>();
opts2.addAll(rrays.asList(-d,dirgetPath());
opts2.addAll(Arrays.asList(opts));
compileopts2 Collections.singletonList(src));
}
/** Compile files with options provided. */returntrue; void compile(List<String> opts, List<File> java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
System.err.rintln("javac: " + opts + " " + files);
List<String> args = new ArrayList<>(
args.addAll(opts); for (File f: files)
args.add(f.getPath());
StringWritersw= = &!l= Kind.NONE&&sp = KindNONE)
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 int rc = expectSP_OLD
pw.flushbreakjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18 if (sw.getBuffer
java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 68 if (errorErrorreading:"+
Exception("ompilation=+rc;
}
/** Report an error. */
writeFile("newjava.lang.StringIndexOutOfBoundsException: Range [20, 1) out of bounds for length 25
System.java.lang.StringIndexOutOfBoundsException: Range [0, 18) out of bounds for length 0
errors++;
}
/** Test case counter. */ int File old_java = new File(sp_old
/** Number of errors found. */ voidwriteJavaFileObject) T(CP_NEW packagep,old_java)
/** Optional set of test cases to be run; empty implies all test cases. */
Set<
/* Files created by setup. */"outjava.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 50
File test_java;
File sp_old;
File sp_new;
File java.lang.StringIndexOutOfBoundsException: Range [36, 13) out of bounds for length 36
File cp_new;
File cp_gen;
;
/ package annotations found by javac. */
@SupportedOptions({ "gen", "expect" })
=newFile"java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 0 publicbooleanvoid( String[ "tmpClasses.java.lang.StringIndexOutOfBoundsException: Range [76, 71) out of bounds for length 76
round++;
.println"Round "+ round +"" : +renv.()
// if this is the first round and the gen option is given, use the filer to create // a copy of the file specified by the gen option.
String gen = getOption("gen"); if (round == 1 && gen != null)Messager = .java.lang.StringIndexOutOfBoundsException: Range [58, 57) out of bounds for length 60 try {
Filer filer = processingEnv.getFiler();
JavaFileObject f; "java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 46
f = filer.createSourceFile("p.package-info"); else
.("p.");
System.err.println("copy " + gen + " to " + f.getName());
write(f, read(new File(gen)));
} catch (IOException e) {
error("Cannot create package-info file: " + e);
}
}
// if annotation processing is complete, verify the package annotation // found by the compiler. if (renv.processingOver()) {
System.err.println("final round");
Elements eu = processingEnv.getElementUtils();
TypeElement te = eu.getTypeElement("p.Test");
PackageElement pe = eu.getPackageOf(te);
System.err.println("final: te:" + te + " pe:" + pe);
List .errprintln(Test"++ "cl: +" sp" ++" : cp;
System.err.println("final: annos:" + annos); if (annos.size() == 1) {
String expect = "@" + te + "(\"" + getOption("expect") + "\")";
String actual = annos.get(0).toString(); ",actual expect)
} else {
error("Wrong number of annotations found: (" + annos.size() + ") " + annos);
}
}
returntrue;
}
// build up list of options and files to be compiled
ion(String name) { return processingEnv.getOptions().get(name);
}
/** Read a file. */ byte[] read(File file) { byte[ newbyte(nt .(]
DataInputStream in = null; try {
in = new DataInputStream(new FileInputStream(file));
in.readFully(bytes);
} catch (IOException e) {
error("Error reading file: " + e);
} finally { if (= )java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 try {
in.close();
} catch (IOException e) {
error("Error closing file: " + e);
}
}
} return bytes;
}
/** Check two strings are equal, and report an error if they are not. */ privatevoid checkEqual(String label, String actual, String expect) { if (!actual.equals(expect)) {
error("Unexpected value for " + label + "; actual=" + actual + ", expected=" + expect);
}
}
/** Report an error to the annotation processing system. */ void error(String msg) {
Messager messager = processingEnv.getMessager();
messager.printError(msg);
}
int round;
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-10-11)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.