issue_id
int64
2.04k
425k
title
stringlengths
9
251
body
stringlengths
4
32.8k
status
stringclasses
6 values
after_fix_sha
stringlengths
7
7
project_name
stringclasses
6 values
repo_url
stringclasses
6 values
repo_name
stringclasses
6 values
language
stringclasses
1 value
issue_url
null
before_fix_sha
null
pull_url
null
commit_datetime
timestamp[us, tz=UTC]
report_datetime
timestamp[us, tz=UTC]
updated_file
stringlengths
23
187
chunk_content
stringlengths
1
22k
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
/** * Complete the destination directory * by copying resources from the source root directories * (if the filter is specified) * and non-.class files from the input jars * (if XCopyInjars is enabled). */ private void completeDestdir() { if (!copyInjars && (null == sourceRootCopyFilter) && (null == inpathDirCopyFilter)) { return; } else if ((destDir == DEFAULT_DESTDIR) || !destDir.canWrite()) { String s = "unable to copy resources to destDir: " + destDir; throw new BuildException(s); } final Project project = getProject(); if (copyInjars) { if (null != inpath) { log("copyInjars does not support inpath.\n", Project.MSG_WARN); } String taskName = getTaskName() + " - unzip"; String[] paths = injars.list(); if (!LangUtil.isEmpty(paths)) { PatternSet patternSet = new PatternSet(); patternSet.setProject(project); patternSet.setIncludes("**/*"); patternSet.setExcludes("**/*.class"); for (int i = 0; i < paths.length; i++) { Expand unzip = new Expand();
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
unzip.setProject(project); unzip.setTaskName(taskName); unzip.setDest(destDir); unzip.setSrc(new File(paths[i])); unzip.addPatternset(patternSet); unzip.execute(); } } } if ((null != sourceRootCopyFilter) && (null != sourceRoots)) { String[] paths = sourceRoots.list(); if (!LangUtil.isEmpty(paths)) { Copy copy = new Copy(); copy.setProject(project); copy.setTodir(destDir); for (int i = 0; i < paths.length; i++) { FileSet fileSet = new FileSet(); fileSet.setDir(new File(paths[i])); fileSet.setIncludes("**/*"); fileSet.setExcludes(sourceRootCopyFilter); copy.addFileset(fileSet); } copy.execute(); } } if ((null != inpathDirCopyFilter) && (null != inpath)) { String[] paths = inpath.list(); if (!LangUtil.isEmpty(paths)) { Copy copy = new Copy(); copy.setProject(project);
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
copy.setTodir(destDir); boolean gotDir = false; for (int i = 0; i < paths.length; i++) { File inpathDir = new File(paths[i]); if (inpathDir.isDirectory() && inpathDir.canRead()) { if (!gotDir) { gotDir = true; } FileSet fileSet = new FileSet(); fileSet.setDir(inpathDir); fileSet.setIncludes("**/*"); fileSet.setExcludes(inpathDirCopyFilter); copy.addFileset(fileSet); } } if (gotDir) { copy.execute(); } } } } /** * Complete the output jar * by copying resources from the source root directories * if the filter is specified. * and non-.class files from the input jars if enabled. */ private void completeOutjar() { if (((null == tmpOutjar) || !tmpOutjar.canRead())
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
|| (!copyInjars && (null == sourceRootCopyFilter) && (null == inpathDirCopyFilter))) { return; } Zip zip = new Zip(); Project project = getProject(); zip.setProject(project); zip.setTaskName(getTaskName() + " - zip"); zip.setDestFile(outjar); ZipFileSet zipfileset = new ZipFileSet(); zipfileset.setProject(project); zipfileset.setSrc(tmpOutjar); zipfileset.setIncludes("**/*.class"); zip.addZipfileset(zipfileset); if (copyInjars) { String[] paths = injars.list(); if (!LangUtil.isEmpty(paths)) { for (int i = 0; i < paths.length; i++) { File jarFile = new File(paths[i]); zipfileset = new ZipFileSet(); zipfileset.setProject(project); zipfileset.setSrc(jarFile); zipfileset.setIncludes("**/*"); zipfileset.setExcludes("**/*.class"); zip.addZipfileset(zipfileset); } } } if ((null != sourceRootCopyFilter) && (null != sourceRoots)) { String[] paths = sourceRoots.list();
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
if (!LangUtil.isEmpty(paths)) { for (int i = 0; i < paths.length; i++) { File srcRoot = new File(paths[i]); FileSet fileset = new FileSet(); fileset.setProject(project); fileset.setDir(srcRoot); fileset.setIncludes("**/*"); fileset.setExcludes(sourceRootCopyFilter); zip.addFileset(fileset); } } } if ((null != inpathDirCopyFilter) && (null != inpath)) { String[] paths = inpath.list(); if (!LangUtil.isEmpty(paths)) { for (int i = 0; i < paths.length; i++) { File inpathDir = new File(paths[i]); if (inpathDir.isDirectory() && inpathDir.canRead()) { FileSet fileset = new FileSet(); fileset.setProject(project); fileset.setDir(inpathDir); fileset.setIncludes("**/*"); fileset.setExcludes(inpathDirCopyFilter); zip.addFileset(fileset); } } } } zip.execute(); }
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
/** * Add specified source files. */ void addFiles(File[] paths) { for (int i = 0; i < paths.length; i++) { addFile(paths[i]); } } /** * Add specified source file. */ void addFile(File path) { if (null != path) { adapterFiles.add(path); } } /** * Read arguments in as if from a command line, * mainly to support compiler adapter compilerarg subelement. * * @param args the String[] of arguments to read */ public void readArguments(String[] args) { if ((null == args) || (0 == args.length)) { return; } class Args {
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
final String[] args; int index = 0; Args(String[] args) { this.args = args; } boolean hasNext() { return index < args.length; } String next() { String err = null; if (!hasNext()) { err = "need arg for flag " + args[args.length-1]; } else { String s = args[index++]; if (null == s) { err = "null value"; } else { s = s.trim(); if (0 == s.trim().length()) { err = "no value"; } else { return s; } } } err += " at [" + index + "] of " + Arrays.asList(args); throw new BuildException(err); }
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
} Args in = new Args(args); String flag; while (in.hasNext()) { flag = in.next(); if ("-1.3".equals(flag)) { setCompliance(flag); } else if ("-1.4".equals(flag)) { setCompliance(flag); } else if ("-1.5".equals(flag)) { setCompliance("1.5"); } else if ("-argfile".equals(flag)) { setArgfiles(new Path(project, in.next())); } else if ("-aspectpath".equals(flag)) { setAspectpath(new Path(project, in.next())); } else if ("-classpath".equals(flag)) { setClasspath(new Path(project, in.next())); } else if ("-extdirs".equals(flag)) { setExtdirs(new Path(project, in.next())); } else if ("-Xcopyinjars".equals(flag)) { setCopyInjars(true); } else if ("-g".equals(flag)) { setDebug(true); } else if (flag.startsWith("-g:")) { setDebugLevel(flag.substring(2)); } else if ("-deprecation".equals(flag)) { setDeprecation(true); } else if ("-d".equals(flag)) { setDestdir(new File(in.next())); } else if ("-crossrefs".equals(flag)) {
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
setCrossrefs(true); } else if ("-emacssym".equals(flag)) { setEmacssym(true); } else if ("-encoding".equals(flag)) { setEncoding(in.next()); } else if ("-Xfailonerror".equals(flag)) { setFailonerror(true); } else if ("-fork".equals(flag)) { setFork(true); } else if ("-forkclasspath".equals(flag)) { setForkclasspath(new Path(project, in.next())); } else if ("-help".equals(flag)) { setHelp(true); } else if ("-incremental".equals(flag)) { setIncremental(true); } else if ("-injars".equals(flag)) { setInjars(new Path(project, in.next())); } else if ("-inpath".equals(flag)) { setInpath(new Path(project,in.next())); } else if ("-Xlistfileargs".equals(flag)) { setListFileArgs(true); } else if ("-Xmaxmem".equals(flag)) { setMaxmem(in.next()); } else if ("-Xmessageholderclass".equals(flag)) { setMessageHolderClass(in.next()); } else if ("-noexit".equals(flag)) { setNoExit(true); } else if ("-noimport".equals(flag)) { setNoExit(true); } else if ("-noExit".equals(flag)) {
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
setNoExit(true); } else if ("-noImportError".equals(flag)) { setNoImportError(true); } else if ("-noWarn".equals(flag)) { setNowarn(true); } else if ("-noexit".equals(flag)) { setNoExit(true); } else if ("-outjar".equals(flag)) { setOutjar(new File(in.next())); } else if ("-outxml".equals(flag)) { setOutxml(true); } else if ("-outxmlfile".equals(flag)) { setOutxmlfile(in.next()); } else if ("-preserveAllLocals".equals(flag)) { setPreserveAllLocals(true); } else if ("-proceedOnError".equals(flag)) { setProceedOnError(true); } else if ("-referenceInfo".equals(flag)) { setReferenceInfo(true); } else if ("-source".equals(flag)) { setSource(in.next()); } else if ("-Xsourcerootcopyfilter".equals(flag)) { setSourceRootCopyFilter(in.next()); } else if ("-sourceroots".equals(flag)) { setSourceRoots(new Path(project, in.next())); } else if ("-Xsrcdir".equals(flag)) { setSrcDir(new Path(project, in.next())); } else if ("-Xtagfile".equals(flag)) { setTagFile(new File(in.next())); } else if ("-target".equals(flag)) {
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
setTarget(in.next()); } else if ("-time".equals(flag)) { setTime(true); } else if ("-time".equals(flag)) { setTime(true); } else if ("-verbose".equals(flag)) { setVerbose(true); } else if ("-showWeaveInfo".equals(flag)) { setShowWeaveInfo(true); } else if ("-version".equals(flag)) { setVersion(true); } else if ("-warn".equals(flag)) { setWarn(in.next()); } else if (flag.startsWith("-warn:")) { setWarn(flag.substring(6)); } else if ("-Xlint".equals(flag)) { setXlintwarnings(true); } else if (flag.startsWith("-Xlint:")) { setXlint(flag.substring(7)); } else if ("-Xlintfile".equals(flag)) { setXlintfile(new File(in.next())); } else if ("-XterminateAfterCompilation".equals(flag)) { setXTerminateAfterCompilation(true); } else if ("-Xreweavable".equals(flag)) { setXReweavable(true); } else if ("-XnotReweavable".equals(flag)) { setXNotReweavable(true); } else if (flag.startsWith("@")) { File file = new File(flag.substring(1)); if (file.canRead()) {
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
setArgfiles(new Path(project, file.getPath())); } else { ignore(flag); } } else { File file = new File(flag); if (file.isFile() && file.canRead() && FileUtil.hasSourceSuffix(file)) { addFile(file); } else { ignore(flag); } } } } protected void logVerbose(String text) { if (this.verbose) { this.logger.info(text); } else { this.logger.verbose(text); } } /** * Commandline wrapper that * only permits addition of non-empty values * and converts to argfile form if necessary. */ public static class GuardedCommand {
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
Commandline command; static boolean isEmpty(String s) { return ((null == s) || (0 == s.trim().length())); } GuardedCommand() { command = new Commandline();
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
} void addFlag(String flag, boolean doAdd) { if (doAdd && !isEmpty(flag)) { command.createArgument().setValue(flag); } } String addOption(String prefix, String[] validOptions, String input) { if (isEmpty(input)) { return null; } for (int i = 0; i < validOptions.length; i++) { if (input.equals(validOptions[i])) { if (isEmpty(prefix)) { addFlag(input, true); } else { addFlagged(prefix, input); } return null; } } return (null == prefix ? input : prefix + " " + input); } void addFlagged(String flag, String argument) { if (!isEmpty(flag) && !isEmpty(argument)) { command.addArguments(new String[] {flag, argument});
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
} } List extractArguments() { ArrayList result = new ArrayList(); String[] cmds = command.getArguments(); if (!LangUtil.isEmpty(cmds)) { result.addAll(Arrays.asList(cmds)); } return result; } /** * Adjust args for size if necessary by creating * an argument file, which should be deleted by the client * after the compiler run has completed. * @param max the int maximum length of the command line (in char) * @return the temp File for the arguments (if generated), * for deletion when done. * @throws IllegalArgumentException if max is negative */ static String[] limitTo(String[] args, int max, Location location) { if (max < 0) { throw new IllegalArgumentException("negative max: " + max); } int size = 0; for (int i = 0; (i < args.length) && (size < max); i++) { size += 1 + (null == args[i] ? 0 : args[i].length());
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
} if (size <= max) { return args; } File tmpFile = null; PrintWriter out = null; try { String userDirName = System.getProperty("user.dir"); File userDir = new File(userDirName); tmpFile = File.createTempFile("argfile", "", userDir); out = new PrintWriter(new FileWriter(tmpFile)); for (int i = 0; i < args.length; i++) { out.println(args[i]); } out.flush(); return new String[] {"-argfile", tmpFile.getAbsolutePath()}; } catch (IOException e) { throw new BuildException("Error creating temporary file", e, location); } finally { if (out != null) { try {out.close();} catch (Throwable t) {} } } } } private static class AntMessageHandler implements IMessageHandler { private TaskLogger logger; private final boolean taskLevelVerbose;
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
private final boolean handledMessage; public AntMessageHandler(TaskLogger logger, boolean taskVerbose, boolean handledMessage) { this.logger = logger; this.taskLevelVerbose = taskVerbose; this.handledMessage = handledMessage; } /* (non-Javadoc) * @see org.aspectj.bridge.IMessageHandler#handleMessage(org.aspectj.bridge.IMessage) */ public boolean handleMessage(IMessage message) throws AbortException { Kind messageKind = message.getKind(); String messageText = message.toString(); if (messageKind == IMessage.ABORT) { this.logger.error(messageText); } else if (messageKind == IMessage.DEBUG) { this.logger.debug(messageText); } else if (messageKind == IMessage.ERROR) { this.logger.error(messageText); } else if (messageKind == IMessage.FAIL){ this.logger.error(messageText); } else if (messageKind == IMessage.INFO) { if (this.taskLevelVerbose) { this.logger.info(messageText); } else { this.logger.verbose(messageText); } } else if (messageKind == IMessage.WARNING) {
224,962
Bug 224962 AjcTask doesn't work with Java6
Although support for Java6 has been added in the last milestone, you can't use it from ant because AjcTask doesn't recognize the "source=1.6" and "target=1.6" parameters. It's easy to fix by modifying AjcTask.java and adding the missing constants: static final String[] TARGET_INPUTS = new String [] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" }; static final String[] SOURCE_INPUTS = new String [] { "1.3", "1.4", "1.5", "1.6" }; static final String[] COMPLIANCE_INPUTS = new String [] { "-1.3", "-1.4", "-1.5", "-1.6" }; Thanks.
resolved fixed
6bdb87d
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-01T04:48:31Z
2008-03-31T19:00:00Z
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
this.logger.warning(messageText); } else if (messageKind == IMessage.WEAVEINFO) { this.logger.info(messageText); } else if (messageKind == IMessage.TASKTAG) { } else { throw new BuildException("Unknown message kind from AspectJ compiler: " + messageKind.toString()); } return handledMessage; } /* (non-Javadoc) * @see org.aspectj.bridge.IMessageHandler#isIgnoring(org.aspectj.bridge.IMessage.Kind) */ public boolean isIgnoring(Kind kind) { return false; } /* (non-Javadoc) * @see org.aspectj.bridge.IMessageHandler#dontIgnore(org.aspectj.bridge.IMessage.Kind) */ public void dontIgnore(Kind kind) { } /* (non-Javadoc) * @see org.aspectj.bridge.IMessageHandler#ignore(org.aspectj.bridge.IMessage.Kind) */ public void ignore(Kind kind) { } } }
228,633
Bug 228633 AST Support for PointcutDesignators
I would like an enhancement to be able to match two PointcutDesignators (called 'pointcut definitions' in the AJ5 quick reference). Currently, the following test fails: ---------------AjASTMatcherTest.java--------------- public void testMatchDefaultPointcut() { AjAST ast = AjAST.newAjAST(AST.JLS3); DefaultPointcut dp1 = ast.newDefaultPointcut(); DefaultPointcut dp2 = ast.newDefaultPointcut(); dp1.setDetail("call(* *.foo(..)"); dp2.setDetail("call(* *.bar(..)"); assertFalse(dp1.subtreeMatch(new AjASTMatcher(), dp2)); } --------------------------------------------------- The reason is that there are no implementations for the many different kinds of pointcut definitions of AspectJ. Instead, DefaultPointcut simply contains the pointcut definition in a String-field "detail" as shown in the test case. The same is true for DefaultTypePattern and SignaturePattern. Additionally, in the current implementation a DefaultPointcut, DefaultTypePattern, and SignaturePattern node will always match another AST node if that node is of the same type (instanceof). From what I see, it is necessary to 1) add types for every possible pointcut definition, 2) extend the current implementation of type name patterns and 3) signature patterns, 4) extend the parser (internal and external?) to create nodes for the pointcut definitions, 5) extend the converter to convert the new node types, and finally 6) extend the matcher to be able to match two pointcut definitions. Implementation is already done for combinations of poincuts using and (&&), or (||), not (!), cflow, and reference pointcuts (without parameters). Please comment on the task list as it is just an initial overview resulting from my limited knowledge on this field.
resolved fixed
bed3f4e
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-24T16:45:17Z
2008-04-24T09:40:00Z
org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTMatcher.java
/******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.aspectj.org.eclipse.jdt.core.dom; public class AjASTMatcher extends ASTMatcher { /** * Creates a new AST matcher instance.
228,633
Bug 228633 AST Support for PointcutDesignators
I would like an enhancement to be able to match two PointcutDesignators (called 'pointcut definitions' in the AJ5 quick reference). Currently, the following test fails: ---------------AjASTMatcherTest.java--------------- public void testMatchDefaultPointcut() { AjAST ast = AjAST.newAjAST(AST.JLS3); DefaultPointcut dp1 = ast.newDefaultPointcut(); DefaultPointcut dp2 = ast.newDefaultPointcut(); dp1.setDetail("call(* *.foo(..)"); dp2.setDetail("call(* *.bar(..)"); assertFalse(dp1.subtreeMatch(new AjASTMatcher(), dp2)); } --------------------------------------------------- The reason is that there are no implementations for the many different kinds of pointcut definitions of AspectJ. Instead, DefaultPointcut simply contains the pointcut definition in a String-field "detail" as shown in the test case. The same is true for DefaultTypePattern and SignaturePattern. Additionally, in the current implementation a DefaultPointcut, DefaultTypePattern, and SignaturePattern node will always match another AST node if that node is of the same type (instanceof). From what I see, it is necessary to 1) add types for every possible pointcut definition, 2) extend the current implementation of type name patterns and 3) signature patterns, 4) extend the parser (internal and external?) to create nodes for the pointcut definitions, 5) extend the converter to convert the new node types, and finally 6) extend the matcher to be able to match two pointcut definitions. Implementation is already done for combinations of poincuts using and (&&), or (||), not (!), cflow, and reference pointcuts (without parameters). Please comment on the task list as it is just an initial overview resulting from my limited knowledge on this field.
resolved fixed
bed3f4e
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-24T16:45:17Z
2008-04-24T09:40:00Z
org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTMatcher.java
* <p> * For backwards compatibility, the matcher ignores tag * elements below doc comments by default. Use * {@link #ASTMatcher(boolean) ASTMatcher(true)} * for a matcher that compares doc tags by default. * </p> */ public AjASTMatcher() { this(false); } /** * Creates a new AST matcher instance. * * @param matchDocTags <code>true</code> if doc comment tags are * to be compared by default, and <code>false</code> otherwise * @see #match(Javadoc,Object) * @since 3.0 */ public AjASTMatcher(boolean matchDocTags) { super(matchDocTags); } public boolean match(PointcutDeclaration node, Object other) { if (!(other instanceof PointcutDeclaration)) { return false; } PointcutDeclaration o = (PointcutDeclaration) other; int level = node.getAST().apiLevel; if (level == AST.JLS2_INTERNAL) { if (node.getModifiers() != o.getModifiers()) {
228,633
Bug 228633 AST Support for PointcutDesignators
I would like an enhancement to be able to match two PointcutDesignators (called 'pointcut definitions' in the AJ5 quick reference). Currently, the following test fails: ---------------AjASTMatcherTest.java--------------- public void testMatchDefaultPointcut() { AjAST ast = AjAST.newAjAST(AST.JLS3); DefaultPointcut dp1 = ast.newDefaultPointcut(); DefaultPointcut dp2 = ast.newDefaultPointcut(); dp1.setDetail("call(* *.foo(..)"); dp2.setDetail("call(* *.bar(..)"); assertFalse(dp1.subtreeMatch(new AjASTMatcher(), dp2)); } --------------------------------------------------- The reason is that there are no implementations for the many different kinds of pointcut definitions of AspectJ. Instead, DefaultPointcut simply contains the pointcut definition in a String-field "detail" as shown in the test case. The same is true for DefaultTypePattern and SignaturePattern. Additionally, in the current implementation a DefaultPointcut, DefaultTypePattern, and SignaturePattern node will always match another AST node if that node is of the same type (instanceof). From what I see, it is necessary to 1) add types for every possible pointcut definition, 2) extend the current implementation of type name patterns and 3) signature patterns, 4) extend the parser (internal and external?) to create nodes for the pointcut definitions, 5) extend the converter to convert the new node types, and finally 6) extend the matcher to be able to match two pointcut definitions. Implementation is already done for combinations of poincuts using and (&&), or (||), not (!), cflow, and reference pointcuts (without parameters). Please comment on the task list as it is just an initial overview resulting from my limited knowledge on this field.
resolved fixed
bed3f4e
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-24T16:45:17Z
2008-04-24T09:40:00Z
org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTMatcher.java
return false; } } if (level >= AST.JLS3) { if (!safeSubtreeListMatch(node.modifiers(), o.modifiers())) { return false; } } return safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) && safeSubtreeMatch(node.getName(), o.getName()) && safeSubtreeMatch(node.getDesignator(), o.getDesignator()); } public boolean match(DefaultPointcut node, Object other) { return (other instanceof DefaultPointcut); } public boolean match(ReferencePointcut node, Object other) { if (!(other instanceof ReferencePointcut)) { return false; } ReferencePointcut o = (ReferencePointcut) other; int level = node.getAST().apiLevel; return safeSubtreeMatch(node.getName(), o.getName()); } public boolean match(NotPointcut node, Object other) { if (!(other instanceof NotPointcut)) {
228,633
Bug 228633 AST Support for PointcutDesignators
I would like an enhancement to be able to match two PointcutDesignators (called 'pointcut definitions' in the AJ5 quick reference). Currently, the following test fails: ---------------AjASTMatcherTest.java--------------- public void testMatchDefaultPointcut() { AjAST ast = AjAST.newAjAST(AST.JLS3); DefaultPointcut dp1 = ast.newDefaultPointcut(); DefaultPointcut dp2 = ast.newDefaultPointcut(); dp1.setDetail("call(* *.foo(..)"); dp2.setDetail("call(* *.bar(..)"); assertFalse(dp1.subtreeMatch(new AjASTMatcher(), dp2)); } --------------------------------------------------- The reason is that there are no implementations for the many different kinds of pointcut definitions of AspectJ. Instead, DefaultPointcut simply contains the pointcut definition in a String-field "detail" as shown in the test case. The same is true for DefaultTypePattern and SignaturePattern. Additionally, in the current implementation a DefaultPointcut, DefaultTypePattern, and SignaturePattern node will always match another AST node if that node is of the same type (instanceof). From what I see, it is necessary to 1) add types for every possible pointcut definition, 2) extend the current implementation of type name patterns and 3) signature patterns, 4) extend the parser (internal and external?) to create nodes for the pointcut definitions, 5) extend the converter to convert the new node types, and finally 6) extend the matcher to be able to match two pointcut definitions. Implementation is already done for combinations of poincuts using and (&&), or (||), not (!), cflow, and reference pointcuts (without parameters). Please comment on the task list as it is just an initial overview resulting from my limited knowledge on this field.
resolved fixed
bed3f4e
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-24T16:45:17Z
2008-04-24T09:40:00Z
org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTMatcher.java
return false; } NotPointcut o = (NotPointcut) other; return safeSubtreeMatch(node.getBody(), o.getBody()); } public boolean match(PerObject node, Object other) { if (!(other instanceof PerObject)) { return false; } PerObject o = (PerObject) other; return safeSubtreeMatch(node.getBody(), o.getBody()) && o.isThis() == node.isThis(); } public boolean match(PerCflow node, Object other) { if (!(other instanceof PerCflow)) { return false; } PerCflow o = (PerCflow) other; return safeSubtreeMatch(node.getBody(), o.getBody()) && node.isBelow() == o.isBelow(); } public boolean match(PerTypeWithin node, Object other) { if (!(other instanceof PerTypeWithin)) { return false; } PerTypeWithin o = (PerTypeWithin) other; return true; } public boolean match(CflowPointcut node, Object other) { if (!(other instanceof CflowPointcut)) {
228,633
Bug 228633 AST Support for PointcutDesignators
I would like an enhancement to be able to match two PointcutDesignators (called 'pointcut definitions' in the AJ5 quick reference). Currently, the following test fails: ---------------AjASTMatcherTest.java--------------- public void testMatchDefaultPointcut() { AjAST ast = AjAST.newAjAST(AST.JLS3); DefaultPointcut dp1 = ast.newDefaultPointcut(); DefaultPointcut dp2 = ast.newDefaultPointcut(); dp1.setDetail("call(* *.foo(..)"); dp2.setDetail("call(* *.bar(..)"); assertFalse(dp1.subtreeMatch(new AjASTMatcher(), dp2)); } --------------------------------------------------- The reason is that there are no implementations for the many different kinds of pointcut definitions of AspectJ. Instead, DefaultPointcut simply contains the pointcut definition in a String-field "detail" as shown in the test case. The same is true for DefaultTypePattern and SignaturePattern. Additionally, in the current implementation a DefaultPointcut, DefaultTypePattern, and SignaturePattern node will always match another AST node if that node is of the same type (instanceof). From what I see, it is necessary to 1) add types for every possible pointcut definition, 2) extend the current implementation of type name patterns and 3) signature patterns, 4) extend the parser (internal and external?) to create nodes for the pointcut definitions, 5) extend the converter to convert the new node types, and finally 6) extend the matcher to be able to match two pointcut definitions. Implementation is already done for combinations of poincuts using and (&&), or (||), not (!), cflow, and reference pointcuts (without parameters). Please comment on the task list as it is just an initial overview resulting from my limited knowledge on this field.
resolved fixed
bed3f4e
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-24T16:45:17Z
2008-04-24T09:40:00Z
org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTMatcher.java
return false; } CflowPointcut o = (CflowPointcut) other; return safeSubtreeMatch(node.getBody(), o.getBody()); } public boolean match(AndPointcut node, Object other) { if (!(other instanceof AndPointcut)) { return false; } AndPointcut o = (AndPointcut) other; return safeSubtreeMatch(node.getLeft(), o.getLeft()) && safeSubtreeMatch(node.getRight(), o.getRight()); } public boolean match(OrPointcut node, Object other) { if (!(other instanceof OrPointcut)) { return false; } OrPointcut o = (OrPointcut) other; return safeSubtreeMatch(node.getLeft(), o.getLeft()) && safeSubtreeMatch(node.getRight(), o.getRight()); } public boolean match(BeforeAdviceDeclaration node, Object other) { if (!(other instanceof BeforeAdviceDeclaration)) { return false; } BeforeAdviceDeclaration o = (BeforeAdviceDeclaration) other; return safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) && safeSubtreeListMatch(node.parameters(), o.parameters()) && safeSubtreeMatch(node.getPointcut(), o.getPointcut())
228,633
Bug 228633 AST Support for PointcutDesignators
I would like an enhancement to be able to match two PointcutDesignators (called 'pointcut definitions' in the AJ5 quick reference). Currently, the following test fails: ---------------AjASTMatcherTest.java--------------- public void testMatchDefaultPointcut() { AjAST ast = AjAST.newAjAST(AST.JLS3); DefaultPointcut dp1 = ast.newDefaultPointcut(); DefaultPointcut dp2 = ast.newDefaultPointcut(); dp1.setDetail("call(* *.foo(..)"); dp2.setDetail("call(* *.bar(..)"); assertFalse(dp1.subtreeMatch(new AjASTMatcher(), dp2)); } --------------------------------------------------- The reason is that there are no implementations for the many different kinds of pointcut definitions of AspectJ. Instead, DefaultPointcut simply contains the pointcut definition in a String-field "detail" as shown in the test case. The same is true for DefaultTypePattern and SignaturePattern. Additionally, in the current implementation a DefaultPointcut, DefaultTypePattern, and SignaturePattern node will always match another AST node if that node is of the same type (instanceof). From what I see, it is necessary to 1) add types for every possible pointcut definition, 2) extend the current implementation of type name patterns and 3) signature patterns, 4) extend the parser (internal and external?) to create nodes for the pointcut definitions, 5) extend the converter to convert the new node types, and finally 6) extend the matcher to be able to match two pointcut definitions. Implementation is already done for combinations of poincuts using and (&&), or (||), not (!), cflow, and reference pointcuts (without parameters). Please comment on the task list as it is just an initial overview resulting from my limited knowledge on this field.
resolved fixed
bed3f4e
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-24T16:45:17Z
2008-04-24T09:40:00Z
org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTMatcher.java
&& safeSubtreeListMatch(node.thrownExceptions(), o.thrownExceptions()) && safeSubtreeMatch(node.getBody(), o.getBody()); } public boolean match(AfterAdviceDeclaration node, Object other) { if (!(other instanceof AfterAdviceDeclaration)) { return false; } AfterAdviceDeclaration o = (AfterAdviceDeclaration) other; return safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) && safeSubtreeListMatch(node.parameters(), o.parameters()) && safeSubtreeMatch(node.getPointcut(), o.getPointcut()) && safeSubtreeListMatch(node.thrownExceptions(), o.thrownExceptions()) && safeSubtreeMatch(node.getBody(), o.getBody()); } public boolean match(AroundAdviceDeclaration node, Object other) { if (!(other instanceof AroundAdviceDeclaration)) { return false; } AroundAdviceDeclaration o = (AroundAdviceDeclaration) other; int level = node.getAST().apiLevel; if (level == AST.JLS2_INTERNAL) { if (!safeSubtreeMatch(node.internalGetReturnType(), o.internalGetReturnType())) { return false; } } if (level >= AST.JLS3) {
228,633
Bug 228633 AST Support for PointcutDesignators
I would like an enhancement to be able to match two PointcutDesignators (called 'pointcut definitions' in the AJ5 quick reference). Currently, the following test fails: ---------------AjASTMatcherTest.java--------------- public void testMatchDefaultPointcut() { AjAST ast = AjAST.newAjAST(AST.JLS3); DefaultPointcut dp1 = ast.newDefaultPointcut(); DefaultPointcut dp2 = ast.newDefaultPointcut(); dp1.setDetail("call(* *.foo(..)"); dp2.setDetail("call(* *.bar(..)"); assertFalse(dp1.subtreeMatch(new AjASTMatcher(), dp2)); } --------------------------------------------------- The reason is that there are no implementations for the many different kinds of pointcut definitions of AspectJ. Instead, DefaultPointcut simply contains the pointcut definition in a String-field "detail" as shown in the test case. The same is true for DefaultTypePattern and SignaturePattern. Additionally, in the current implementation a DefaultPointcut, DefaultTypePattern, and SignaturePattern node will always match another AST node if that node is of the same type (instanceof). From what I see, it is necessary to 1) add types for every possible pointcut definition, 2) extend the current implementation of type name patterns and 3) signature patterns, 4) extend the parser (internal and external?) to create nodes for the pointcut definitions, 5) extend the converter to convert the new node types, and finally 6) extend the matcher to be able to match two pointcut definitions. Implementation is already done for combinations of poincuts using and (&&), or (||), not (!), cflow, and reference pointcuts (without parameters). Please comment on the task list as it is just an initial overview resulting from my limited knowledge on this field.
resolved fixed
bed3f4e
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-24T16:45:17Z
2008-04-24T09:40:00Z
org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTMatcher.java
if (!safeSubtreeMatch(node.getReturnType2(), o.getReturnType2())) { return false; } if (!safeSubtreeListMatch(node.typeParameters(), o.typeParameters())) { return false; } } return safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) && safeSubtreeListMatch(node.parameters(), o.parameters()) && safeSubtreeMatch(node.getPointcut(), o.getPointcut()) && safeSubtreeListMatch(node.thrownExceptions(), o.thrownExceptions()) && safeSubtreeMatch(node.getBody(), o.getBody()); } public boolean match(DeclareDeclaration node, Object other) { if (!(other instanceof DeclareDeclaration)) { return false; } DeclareDeclaration o = (DeclareDeclaration) other; int level = node.getAST().apiLevel; return safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()); } public boolean match(InterTypeFieldDeclaration node, Object other) { if (!(other instanceof InterTypeFieldDeclaration)) { return false; } InterTypeFieldDeclaration o = (InterTypeFieldDeclaration) other; int level = node.getAST().apiLevel; if (level == AST.JLS2_INTERNAL) {
228,633
Bug 228633 AST Support for PointcutDesignators
I would like an enhancement to be able to match two PointcutDesignators (called 'pointcut definitions' in the AJ5 quick reference). Currently, the following test fails: ---------------AjASTMatcherTest.java--------------- public void testMatchDefaultPointcut() { AjAST ast = AjAST.newAjAST(AST.JLS3); DefaultPointcut dp1 = ast.newDefaultPointcut(); DefaultPointcut dp2 = ast.newDefaultPointcut(); dp1.setDetail("call(* *.foo(..)"); dp2.setDetail("call(* *.bar(..)"); assertFalse(dp1.subtreeMatch(new AjASTMatcher(), dp2)); } --------------------------------------------------- The reason is that there are no implementations for the many different kinds of pointcut definitions of AspectJ. Instead, DefaultPointcut simply contains the pointcut definition in a String-field "detail" as shown in the test case. The same is true for DefaultTypePattern and SignaturePattern. Additionally, in the current implementation a DefaultPointcut, DefaultTypePattern, and SignaturePattern node will always match another AST node if that node is of the same type (instanceof). From what I see, it is necessary to 1) add types for every possible pointcut definition, 2) extend the current implementation of type name patterns and 3) signature patterns, 4) extend the parser (internal and external?) to create nodes for the pointcut definitions, 5) extend the converter to convert the new node types, and finally 6) extend the matcher to be able to match two pointcut definitions. Implementation is already done for combinations of poincuts using and (&&), or (||), not (!), cflow, and reference pointcuts (without parameters). Please comment on the task list as it is just an initial overview resulting from my limited knowledge on this field.
resolved fixed
bed3f4e
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-24T16:45:17Z
2008-04-24T09:40:00Z
org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTMatcher.java
if (node.getModifiers() != o.getModifiers()) { return false; } } if (level >= AST.JLS3) { if (!safeSubtreeListMatch(node.modifiers(), o.modifiers())) { return false; } } return safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) && safeSubtreeMatch(node.getType(), o.getType()) && safeSubtreeListMatch(node.fragments(), o.fragments()); } public boolean match(InterTypeMethodDeclaration node, Object other) { if (!(other instanceof InterTypeMethodDeclaration)) { return false; } InterTypeMethodDeclaration o = (InterTypeMethodDeclaration) other; int level = node.getAST().apiLevel; if (level == AST.JLS2_INTERNAL) { if (node.getModifiers() != o.getModifiers()) { return false; } if (!safeSubtreeMatch(node.internalGetReturnType(), o.internalGetReturnType())) { return false; } } if (level >= AST.JLS3) {
228,633
Bug 228633 AST Support for PointcutDesignators
I would like an enhancement to be able to match two PointcutDesignators (called 'pointcut definitions' in the AJ5 quick reference). Currently, the following test fails: ---------------AjASTMatcherTest.java--------------- public void testMatchDefaultPointcut() { AjAST ast = AjAST.newAjAST(AST.JLS3); DefaultPointcut dp1 = ast.newDefaultPointcut(); DefaultPointcut dp2 = ast.newDefaultPointcut(); dp1.setDetail("call(* *.foo(..)"); dp2.setDetail("call(* *.bar(..)"); assertFalse(dp1.subtreeMatch(new AjASTMatcher(), dp2)); } --------------------------------------------------- The reason is that there are no implementations for the many different kinds of pointcut definitions of AspectJ. Instead, DefaultPointcut simply contains the pointcut definition in a String-field "detail" as shown in the test case. The same is true for DefaultTypePattern and SignaturePattern. Additionally, in the current implementation a DefaultPointcut, DefaultTypePattern, and SignaturePattern node will always match another AST node if that node is of the same type (instanceof). From what I see, it is necessary to 1) add types for every possible pointcut definition, 2) extend the current implementation of type name patterns and 3) signature patterns, 4) extend the parser (internal and external?) to create nodes for the pointcut definitions, 5) extend the converter to convert the new node types, and finally 6) extend the matcher to be able to match two pointcut definitions. Implementation is already done for combinations of poincuts using and (&&), or (||), not (!), cflow, and reference pointcuts (without parameters). Please comment on the task list as it is just an initial overview resulting from my limited knowledge on this field.
resolved fixed
bed3f4e
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-04-24T16:45:17Z
2008-04-24T09:40:00Z
org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom/AjASTMatcher.java
if (!safeSubtreeListMatch(node.modifiers(), o.modifiers())) { return false; } if (!safeSubtreeMatch(node.getReturnType2(), o.getReturnType2())) { return false; } if (!safeSubtreeListMatch(node.typeParameters(), o.typeParameters())) { return false; } } return ((node.isConstructor() == o.isConstructor()) && safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) && safeSubtreeMatch(node.getName(), o.getName()) && safeSubtreeListMatch(node.parameters(), o.parameters()) && node.getExtraDimensions() == o.getExtraDimensions() && safeSubtreeListMatch(node.thrownExceptions(), o.thrownExceptions()) && safeSubtreeMatch(node.getBody(), o.getBody())); } public boolean match(DefaultTypePattern node, Object other) { return (other instanceof DefaultTypePattern); } public boolean match(SignaturePattern node, Object other) { return (other instanceof SignaturePattern); } }
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
/* ******************************************************************* * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). * All rights reserved. * This program and the accompanying materials are made available * under the terms of the Eclipse Public License v1.0 * which accompanies this distribution and is available at * http:www.eclipse.org/legal/epl-v10.html * * Contributors: * PARC initial implementation * ******************************************************************/ package org.aspectj.weaver.bcel; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map;
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
import java.util.Properties; import java.util.Set; import org.aspectj.apache.bcel.Constants; import org.aspectj.apache.bcel.classfile.Field; import org.aspectj.apache.bcel.classfile.Method; import org.aspectj.apache.bcel.classfile.annotation.Annotation; import org.aspectj.apache.bcel.generic.ANEWARRAY; import org.aspectj.apache.bcel.generic.BranchInstruction; import org.aspectj.apache.bcel.generic.CPInstruction; import org.aspectj.apache.bcel.generic.ConstantPoolGen; import org.aspectj.apache.bcel.generic.FieldGen; import org.aspectj.apache.bcel.generic.FieldInstruction; import org.aspectj.apache.bcel.generic.GOTO; import org.aspectj.apache.bcel.generic.GOTO_W; import org.aspectj.apache.bcel.generic.INVOKESPECIAL; import org.aspectj.apache.bcel.generic.IndexedInstruction; import org.aspectj.apache.bcel.generic.Instruction; import org.aspectj.apache.bcel.generic.InstructionConstants; import org.aspectj.apache.bcel.generic.InstructionFactory; import org.aspectj.apache.bcel.generic.InstructionHandle; import org.aspectj.apache.bcel.generic.InstructionList; import org.aspectj.apache.bcel.generic.InstructionTargeter; import org.aspectj.apache.bcel.generic.InvokeInstruction; import org.aspectj.apache.bcel.generic.LineNumberTag; import org.aspectj.apache.bcel.generic.LocalVariableInstruction; import org.aspectj.apache.bcel.generic.LocalVariableTag; import org.aspectj.apache.bcel.generic.MONITORENTER; import org.aspectj.apache.bcel.generic.MONITOREXIT; import org.aspectj.apache.bcel.generic.MULTIANEWARRAY; import org.aspectj.apache.bcel.generic.MethodGen;
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
import org.aspectj.apache.bcel.generic.NEW; import org.aspectj.apache.bcel.generic.NEWARRAY; import org.aspectj.apache.bcel.generic.ObjectType; import org.aspectj.apache.bcel.generic.PUTFIELD; import org.aspectj.apache.bcel.generic.PUTSTATIC; import org.aspectj.apache.bcel.generic.RET; import org.aspectj.apache.bcel.generic.ReturnInstruction; import org.aspectj.apache.bcel.generic.Select; import org.aspectj.apache.bcel.generic.Tag; import org.aspectj.apache.bcel.generic.Type; import org.aspectj.apache.bcel.generic.annotation.AnnotationGen; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.ISourceLocation; import org.aspectj.bridge.Message; import org.aspectj.bridge.MessageUtil; import org.aspectj.bridge.WeaveMessage; import org.aspectj.bridge.context.CompilationAndWeavingContext; import org.aspectj.bridge.context.ContextToken; import org.aspectj.util.PartialOrder; import org.aspectj.weaver.AjAttribute; import org.aspectj.weaver.AjcMemberMaker; import org.aspectj.weaver.AsmRelationshipProvider; import org.aspectj.weaver.BCException; import org.aspectj.weaver.ConcreteTypeMunger; import org.aspectj.weaver.IClassWeaver; import org.aspectj.weaver.IntMap; import org.aspectj.weaver.Member; import org.aspectj.weaver.MissingResolvedTypeWithKnownSignature; import org.aspectj.weaver.NameMangler; import org.aspectj.weaver.NewConstructorTypeMunger;
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
import org.aspectj.weaver.NewFieldTypeMunger; import org.aspectj.weaver.NewMethodTypeMunger; import org.aspectj.weaver.ResolvedMember; import org.aspectj.weaver.ResolvedMemberImpl; import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.ResolvedTypeMunger; import org.aspectj.weaver.Shadow; import org.aspectj.weaver.ShadowMunger; import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.WeaverMessages; import org.aspectj.weaver.WeaverMetrics; import org.aspectj.weaver.WeaverStateInfo; import org.aspectj.weaver.World; import org.aspectj.weaver.patterns.DeclareAnnotation; import org.aspectj.weaver.patterns.ExactTypePattern; import org.aspectj.weaver.tools.Trace; import org.aspectj.weaver.tools.TraceFactory; class BcelClassWeaver implements IClassWeaver { private static Trace trace = TraceFactory.getTraceFactory().getTrace(BcelClassWeaver.class); /** * This is called from {@link BcelWeaver} to perform the per-class weaving process. */ public static boolean weave( BcelWorld world, LazyClassGen clazz, List shadowMungers, List typeMungers, List lateTypeMungers) {
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
boolean b = new BcelClassWeaver(world, clazz, shadowMungers, typeMungers, lateTypeMungers).weave(); return b; } private final LazyClassGen clazz; private final List shadowMungers; private final List typeMungers; private final List lateTypeMungers; private final BcelObjectType ty; private final BcelWorld world; private final ConstantPoolGen cpg; private final InstructionFactory fact; private final List addedLazyMethodGens = new ArrayList(); private final Set addedDispatchTargets = new HashSet(); private static boolean inReweavableMode = false; private List addedSuperInitializersAsList = null; private final Map addedSuperInitializers = new HashMap(); private List addedThisInitializers = new ArrayList(); private List addedClassInitializers = new ArrayList(); private Map mapToAnnotations = new HashMap();
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
private BcelShadow clinitShadow = null; /** * This holds the initialization and pre-initialization shadows for this class * that were actually matched by mungers (if no match, then we don't even create the * shadows really). */ private final List initializationShadows = new ArrayList(1); private BcelClassWeaver( BcelWorld world, LazyClassGen clazz, List shadowMungers, List typeMungers, List lateTypeMungers) { super(); this.world = world; this.clazz = clazz; this.shadowMungers = shadowMungers; this.typeMungers = typeMungers; this.lateTypeMungers = lateTypeMungers; this.ty = clazz.getBcelObjectType(); this.cpg = clazz.getConstantPoolGen(); this.fact = clazz.getFactory(); fastMatchShadowMungers(shadowMungers);
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
initializeSuperInitializerMap(ty.getResolvedTypeX()); if (!checkedXsetForLowLevelContextCapturing) { Properties p = world.getExtraConfiguration(); if (p!=null) { String s = p.getProperty(World.xsetCAPTURE_ALL_CONTEXT,"false"); captureLowLevelContext = s.equalsIgnoreCase("true"); if (captureLowLevelContext) world.getMessageHandler().handleMessage(MessageUtil.info("["+World.xsetCAPTURE_ALL_CONTEXT+"=true] Enabling collection of low level context for debug/crash messages")); } checkedXsetForLowLevelContextCapturing=true; } } private List[] perKindShadowMungers; private boolean canMatchBodyShadows = false; private boolean canMatchInitialization = false; private void fastMatchShadowMungers(List shadowMungers) { perKindShadowMungers = new List[Shadow.MAX_SHADOW_KIND + 1]; for (int i = 0; i < perKindShadowMungers.length; i++) { perKindShadowMungers[i] = new ArrayList(0); } for (Iterator iter = shadowMungers.iterator(); iter.hasNext();) { ShadowMunger munger = (ShadowMunger) iter.next(); int couldMatchKinds = munger.getPointcut().couldMatchKinds(); for (int i = 0; i < Shadow.SHADOW_KINDS.length; i++) { Shadow.Kind kind = Shadow.SHADOW_KINDS[i]; if (kind.isSet(couldMatchKinds)) perKindShadowMungers[kind.getKey()].add(munger);
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
} } if (!perKindShadowMungers[Shadow.Initialization.getKey()].isEmpty()) canMatchInitialization = true; for (int i = 0; i < Shadow.SHADOW_KINDS.length; i++) { Shadow.Kind kind = Shadow.SHADOW_KINDS[i]; if (!kind.isEnclosingKind() && !perKindShadowMungers[i+1].isEmpty()) { canMatchBodyShadows = true; } if (perKindShadowMungers[i+1].isEmpty()) { perKindShadowMungers[i+1] = null; } } } private boolean canMatch(Shadow.Kind kind) { return perKindShadowMungers[kind.getKey()] != null; } } private void initializeSuperInitializerMap(ResolvedType child) { ResolvedType[] superInterfaces = child.getDeclaredInterfaces(); for (int i=0, len=superInterfaces.length; i < len; i++) { if (ty.getResolvedTypeX().isTopmostImplementor(superInterfaces[i])) { if (addSuperInitializer(superInterfaces[i])) { initializeSuperInitializerMap(superInterfaces[i]);
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
} } } } private boolean addSuperInitializer(ResolvedType onType) { if (onType.isRawType() || onType.isParameterizedType()) onType = onType.getGenericType(); IfaceInitList l = (IfaceInitList) addedSuperInitializers.get(onType); if (l != null) return false; l = new IfaceInitList(onType); addedSuperInitializers.put(onType, l); return true; } public void addInitializer(ConcreteTypeMunger cm) { NewFieldTypeMunger m = (NewFieldTypeMunger) cm.getMunger(); ResolvedType onType = m.getSignature().getDeclaringType().resolve(world); if (onType.isRawType()) onType = onType.getGenericType(); if (m.getSignature().isStatic()) { addedClassInitializers.add(cm); } else { if (onType == ty.getResolvedTypeX()) { addedThisInitializers.add(cm); } else { IfaceInitList l = (IfaceInitList) addedSuperInitializers.get(onType); l.list.add(cm); } } } private static class IfaceInitList implements PartialOrder.PartialComparable {
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
final ResolvedType onType; List list = new ArrayList(); IfaceInitList(ResolvedType onType) { this.onType = onType; } public int compareTo(Object other) { IfaceInitList o = (IfaceInitList)other; if (onType.isAssignableFrom(o.onType)) return +1; else if (o.onType.isAssignableFrom(onType)) return -1; else return 0; } public int fallbackCompareTo(Object other) { return 0; } } public boolean addDispatchTarget(ResolvedMember m) { return addedDispatchTargets.add(m);
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
} public void addLazyMethodGen(LazyMethodGen gen) { addedLazyMethodGens.add(gen); } public void addOrReplaceLazyMethodGen(LazyMethodGen mg) { if (alreadyDefined(clazz, mg)) return; for (Iterator i = addedLazyMethodGens.iterator(); i.hasNext(); ) { LazyMethodGen existing = (LazyMethodGen)i.next(); if (signaturesMatch(mg, existing)) { if (existing.definingType == null) { return; } else if (mg.definingType.isAssignableFrom(existing.definingType)) { return; } else if (existing.definingType.isAssignableFrom(mg.definingType)) { i.remove(); addedLazyMethodGens.add(mg); return; } else { throw new BCException("conflict between: " + mg + " and " + existing); } } } addedLazyMethodGens.add(mg); }
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
private boolean alreadyDefined(LazyClassGen clazz, LazyMethodGen mg) { for (Iterator i = clazz.getMethodGens().iterator(); i.hasNext(); ) { LazyMethodGen existing = (LazyMethodGen)i.next(); if (signaturesMatch(mg, existing)) { if (!mg.isAbstract() && existing.isAbstract()) { i.remove(); return false; } return true; } } return false; } private boolean signaturesMatch(LazyMethodGen mg, LazyMethodGen existing) { return mg.getName().equals(existing.getName()) && mg.getSignature().equals(existing.getSignature()); } protected static LazyMethodGen makeBridgeMethod(LazyClassGen gen, ResolvedMember member) { int mods = member.getModifiers(); if (Modifier.isAbstract(mods)) mods = mods - Modifier.ABSTRACT; LazyMethodGen ret = new LazyMethodGen( mods, BcelWorld.makeBcelType(member.getReturnType()), member.getName(), BcelWorld.makeBcelTypes(member.getParameterTypes()), UnresolvedType.getNames(member.getExceptions()),
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
gen); return ret; } /** * Create a single bridge method called 'theBridgeMethod' that bridges to 'whatToBridgeTo' */ private static void createBridgeMethod(BcelWorld world, LazyMethodGen whatToBridgeToMethodGen, LazyClassGen clazz,ResolvedMember theBridgeMethod) { InstructionList body; InstructionFactory fact; int pos = 0; ResolvedMember whatToBridgeTo = whatToBridgeToMethodGen.getMemberView(); if (whatToBridgeTo==null) { whatToBridgeTo = new ResolvedMemberImpl(Member.METHOD, whatToBridgeToMethodGen.getEnclosingClass().getType(), whatToBridgeToMethodGen.getAccessFlags(), whatToBridgeToMethodGen.getName(), whatToBridgeToMethodGen.getSignature()); } LazyMethodGen bridgeMethod = makeBridgeMethod(clazz,theBridgeMethod); bridgeMethod.setAccessFlags(bridgeMethod.getAccessFlags() | 0x00000040 ); Type returnType = BcelWorld.makeBcelType(theBridgeMethod.getReturnType()); Type[] paramTypes = BcelWorld.makeBcelTypes(theBridgeMethod.getParameterTypes()); Type[] newParamTypes=whatToBridgeToMethodGen.getArgumentTypes();
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
body = bridgeMethod.getBody(); fact = clazz.getFactory(); if (!whatToBridgeToMethodGen.isStatic()) { body.append(InstructionFactory.createThis()); pos++; } for (int i = 0, len = paramTypes.length; i < len; i++) { Type paramType = paramTypes[i]; body.append(InstructionFactory.createLoad(paramType, pos)); if (!newParamTypes[i].equals(paramTypes[i])) { if (world.forDEBUG_bridgingCode) System.err.println("Bridging: Cast "+newParamTypes[i]+" from "+paramTypes[i]); body.append(fact.createCast(paramTypes[i],newParamTypes[i])); } pos+=paramType.getSize(); } body.append(Utility.createInvoke(fact, world,whatToBridgeTo)); body.append(InstructionFactory.createReturn(returnType)); clazz.addMethodGen(bridgeMethod); } public boolean weave() { if (clazz.isWoven() && !clazz.isReweavable()) { world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.ALREADY_WOVEN,clazz.getType().getName()), ty.getSourceLocation(), null); return false; }
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
Set aspectsAffectingType = null; if (inReweavableMode || clazz.getType().isAspect()) aspectsAffectingType = new HashSet(); boolean isChanged = false; if (clazz.getType().isAspect()) isChanged = true; for (Iterator i = typeMungers.iterator(); i.hasNext(); ) { Object o = i.next(); if ( !(o instanceof BcelTypeMunger) ) { continue; } BcelTypeMunger munger = (BcelTypeMunger)o; boolean typeMungerAffectedType = munger.munge(this); if (typeMungerAffectedType) { isChanged = true; if (inReweavableMode || clazz.getType().isAspect()) aspectsAffectingType.add(munger.getAspectType().getName()); } } isChanged = weaveDeclareAtMethodCtor(clazz) || isChanged; isChanged = weaveDeclareAtField(clazz) || isChanged; addedSuperInitializersAsList = new ArrayList(addedSuperInitializers.values());
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
addedSuperInitializersAsList = PartialOrder.sort(addedSuperInitializersAsList); if (addedSuperInitializersAsList == null) { throw new BCException("circularity in inter-types"); } LazyMethodGen staticInit = clazz.getStaticInitializer(); staticInit.getBody().insert(genInitInstructions(addedClassInitializers, true)); List methodGens = new ArrayList(clazz.getMethodGens()); for (Iterator i = methodGens.iterator(); i.hasNext();) { LazyMethodGen mg = (LazyMethodGen)i.next(); if (! mg.hasBody()) continue; if (world.isJoinpointSynchronizationEnabled() && world.areSynchronizationPointcutsInUse() && mg.getMethod().isSynchronized()) { transformSynchronizedMethod(mg); } boolean shadowMungerMatched = match(mg); if (shadowMungerMatched) { if (inReweavableMode || clazz.getType().isAspect()) aspectsAffectingType.addAll(findAspectsForMungers(mg)); isChanged = true; } }
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
for (Iterator i = methodGens.iterator(); i.hasNext();) { LazyMethodGen mg = (LazyMethodGen)i.next(); if (! mg.hasBody()) continue; implement(mg); } if (!initializationShadows.isEmpty()) { while (inlineSelfConstructors(methodGens)); positionAndImplement(initializationShadows); } if (lateTypeMungers != null) { for (Iterator i = lateTypeMungers.iterator(); i.hasNext(); ) { BcelTypeMunger munger = (BcelTypeMunger)i.next(); if (munger.matches(clazz.getType())) { boolean typeMungerAffectedType = munger.munge(this); if (typeMungerAffectedType) { isChanged = true; if (inReweavableMode || clazz.getType().isAspect()) aspectsAffectingType.add(munger.getAspectType().getName()); } } } }
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
if (isChanged) { clazz.getOrCreateWeaverStateInfo(inReweavableMode); weaveInAddedMethods(); } if (inReweavableMode) { WeaverStateInfo wsi = clazz.getOrCreateWeaverStateInfo(true); wsi.addAspectsAffectingType(aspectsAffectingType); wsi.setUnwovenClassFileData(ty.getJavaClass().getBytes()); wsi.setReweavable(true); } else { clazz.getOrCreateWeaverStateInfo(false).setReweavable(false); } return isChanged; } /** * Check if a particular method is overriding another - refactored into this helper so it * can be used from multiple places. */ private static ResolvedMember isOverriding(ResolvedType typeToCheck,ResolvedMember methodThatMightBeGettingOverridden,String mname,String mrettype,int mmods,boolean inSamePackage,UnresolvedType[] methodParamsArray) {
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
if (methodThatMightBeGettingOverridden.isStatic()) return null; if (methodThatMightBeGettingOverridden.isPrivate()) return null; if (!methodThatMightBeGettingOverridden.getName().equals(mname)) return null; if (methodThatMightBeGettingOverridden.getParameterTypes().length!=methodParamsArray.length) return null; if (!isVisibilityOverride(mmods,methodThatMightBeGettingOverridden,inSamePackage)) return null; if (typeToCheck.getWorld().forDEBUG_bridgingCode) System.err.println(" Bridging:seriously considering this might be getting overridden '"+methodThatMightBeGettingOverridden+"'"); boolean sameParams = true; for (int p = 0;p<methodThatMightBeGettingOverridden.getParameterTypes().length;p++) { if (!methodThatMightBeGettingOverridden.getParameterTypes()[p].getErasureSignature().equals(methodParamsArray[p].getErasureSignature())) sameParams = false; } if (sameParams) { if (typeToCheck.isParameterizedType()) { return methodThatMightBeGettingOverridden.getBackingGenericMember(); } else if (!methodThatMightBeGettingOverridden.getReturnType().getErasureSignature().equals(mrettype)) { ResolvedType superReturn = typeToCheck.getWorld().resolve(UnresolvedType.forSignature(methodThatMightBeGettingOverridden.getReturnType().getErasureSignature())); ResolvedType subReturn = typeToCheck.getWorld().resolve(UnresolvedType.forSignature(mrettype));
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
if (superReturn.isAssignableFrom(subReturn)) return methodThatMightBeGettingOverridden; } } return null; } /** * Looks at the visibility modifiers between two methods, and knows whether they are from classes in * the same package, and decides whether one overrides the other. * @return true if there is an overrides rather than a 'hides' relationship */ static boolean isVisibilityOverride(int methodMods, ResolvedMember inheritedMethod,boolean inSamePackage) { if (inheritedMethod.isStatic()) return false; if (methodMods == inheritedMethod.getModifiers()) return true; if (inheritedMethod.isPrivate()) return false; boolean isPackageVisible = !inheritedMethod.isPrivate() && !inheritedMethod.isProtected() && !inheritedMethod.isPublic(); if (isPackageVisible && !inSamePackage) return false; return true; } /** * This method recurses up a specified type looking for a method that overrides the one passed in. * * @return the method being overridden or null if none is found */ public static ResolvedMember checkForOverride(ResolvedType typeToCheck,String mname,String mparams,String mrettype,int mmods,String mpkg,UnresolvedType[] methodParamsArray) {
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
if (typeToCheck==null) return null; if (typeToCheck instanceof MissingResolvedTypeWithKnownSignature) return null; if (typeToCheck.getWorld().forDEBUG_bridgingCode) System.err.println(" Bridging:checking for override of "+mname+" in "+typeToCheck); String packageName = typeToCheck.getPackageName(); if (packageName==null) packageName=""; boolean inSamePackage = packageName.equals(mpkg); ResolvedMember [] methods = typeToCheck.getDeclaredMethods(); for (int ii=0;ii<methods.length;ii++) { ResolvedMember methodThatMightBeGettingOverridden = methods[ii]; ResolvedMember isOverriding = isOverriding(typeToCheck,methodThatMightBeGettingOverridden,mname,mrettype,mmods,inSamePackage,methodParamsArray); if (isOverriding!=null) return isOverriding; } List l = typeToCheck.getInterTypeMungers(); for (Iterator iterator = l.iterator(); iterator.hasNext();) { Object o = iterator.next(); if (o instanceof BcelTypeMunger) { BcelTypeMunger element = (BcelTypeMunger)o; if (element.getMunger() instanceof NewMethodTypeMunger) { if (typeToCheck.getWorld().forDEBUG_bridgingCode) System.err.println("Possible ITD candidate "+element); ResolvedMember aMethod = element.getSignature(); ResolvedMember isOverriding = isOverriding(typeToCheck,aMethod,mname,mrettype,mmods,inSamePackage,methodParamsArray); if (isOverriding!=null) return isOverriding; } } }
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
if (typeToCheck.equals(UnresolvedType.OBJECT)) return null; ResolvedType superclass = typeToCheck.getSuperclass(); ResolvedMember overriddenMethod = checkForOverride(superclass,mname,mparams,mrettype,mmods,mpkg,methodParamsArray); if (overriddenMethod!=null) return overriddenMethod; ResolvedType[] interfaces = typeToCheck.getDeclaredInterfaces(); for (int i = 0; i < interfaces.length; i++) { ResolvedType anInterface = interfaces[i]; overriddenMethod = checkForOverride(anInterface,mname,mparams,mrettype,mmods,mpkg,methodParamsArray); if (overriddenMethod!=null) return overriddenMethod; } return null; } /** * We need to determine if any methods in this type require bridge methods - this method should only * be called if necessary to do this calculation, i.e. we are on a 1.5 VM (where covariance/generics exist) and * the type hierarchy for the specified class has changed (via decp/itd). * * See pr108101 */ public static boolean calculateAnyRequiredBridgeMethods(BcelWorld world,LazyClassGen clazz) { world.ensureAdvancedConfigurationProcessed(); if (!world.isInJava5Mode()) return false; if (clazz.isInterface()) return false; boolean didSomething=false; List methods = clazz.getMethodGens();
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
Set methodsSet = new HashSet(); for (int i = 0; i < methods.size(); i++) { LazyMethodGen aMethod = (LazyMethodGen)methods.get(i); methodsSet.add(aMethod.getName()+aMethod.getSignature()); } for (int i = 0; i < methods.size(); i++) { LazyMethodGen bridgeToCandidate = (LazyMethodGen)methods.get(i); if (bridgeToCandidate.isBridgeMethod()) continue; String name = bridgeToCandidate.getName(); String psig = bridgeToCandidate.getParameterSignature(); String rsig = bridgeToCandidate.getReturnType().getSignature(); if (bridgeToCandidate.isStatic()) continue; if (name.endsWith("init>")) continue; if (world.forDEBUG_bridgingCode) System.err.println("Bridging: Determining if we have to bridge to "+clazz.getName()+"."+name+""+bridgeToCandidate.getSignature()); ResolvedType theSuperclass= clazz.getSuperClass(); if (world.forDEBUG_bridgingCode) System.err.println("Bridging: Checking supertype "+theSuperclass); String pkgName = clazz.getPackageName(); UnresolvedType[] bm = BcelWorld.fromBcel(bridgeToCandidate.getArgumentTypes()); ResolvedMember overriddenMethod = checkForOverride(theSuperclass,name,psig,rsig,bridgeToCandidate.getAccessFlags(),pkgName,bm); if (overriddenMethod!=null) {
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
boolean alreadyHaveABridgeMethod = methodsSet.contains(overriddenMethod.getName()+overriddenMethod.getSignature()); if (!alreadyHaveABridgeMethod) { if (world.forDEBUG_bridgingCode) System.err.println("Bridging:bridging to '"+overriddenMethod+"'"); createBridgeMethod(world, bridgeToCandidate, clazz, overriddenMethod); didSomething = true; continue; } } String[] interfaces = clazz.getInterfaceNames(); for (int j = 0; j < interfaces.length; j++) { if (world.forDEBUG_bridgingCode) System.err.println("Bridging:checking superinterface "+interfaces[j]); ResolvedType interfaceType = world.resolve(interfaces[j]); overriddenMethod = checkForOverride(interfaceType,name,psig,rsig,bridgeToCandidate.getAccessFlags(),clazz.getPackageName(),bm); if (overriddenMethod!=null) { boolean alreadyHaveABridgeMethod = methodsSet.contains(overriddenMethod.getName()+overriddenMethod.getSignature()); if (!alreadyHaveABridgeMethod) { createBridgeMethod(world, bridgeToCandidate, clazz, overriddenMethod); didSomething=true; if (world.forDEBUG_bridgingCode) System.err.println("Bridging:bridging to "+overriddenMethod); continue; } } } } return didSomething; } /**
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
* Weave any declare @method/@ctor statements into the members of the supplied class */ private boolean weaveDeclareAtMethodCtor(LazyClassGen clazz) { List reportedProblems = new ArrayList(); List allDecams = world.getDeclareAnnotationOnMethods(); if (allDecams.isEmpty()) return false; boolean isChanged = false; List itdMethodsCtors = getITDSubset(clazz,ResolvedTypeMunger.Method); itdMethodsCtors.addAll(getITDSubset(clazz,ResolvedTypeMunger.Constructor)); if (!itdMethodsCtors.isEmpty()) { isChanged = weaveAtMethodOnITDSRepeatedly(allDecams,itdMethodsCtors,reportedProblems); } List members = clazz.getMethodGens(); List decaMs = getMatchingSubset(allDecams,clazz.getType()); if (decaMs.isEmpty()) return false; if (!members.isEmpty()) { Set unusedDecams = new HashSet(); unusedDecams.addAll(decaMs); for (int memberCounter = 0;memberCounter<members.size();memberCounter++) { LazyMethodGen mg = (LazyMethodGen)members.get(memberCounter); if (!mg.getName().startsWith(NameMangler.PREFIX)) { List worthRetrying = new ArrayList();
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
boolean modificationOccured = false; List annotationsToAdd = null; for (Iterator iter = decaMs.iterator(); iter.hasNext();) { DeclareAnnotation decaM = (DeclareAnnotation) iter.next(); if (decaM.matches(mg.getMemberView(),world)) { if (doesAlreadyHaveAnnotation(mg.getMemberView(),decaM,reportedProblems)) { unusedDecams.remove(decaM); continue; } if (annotationsToAdd==null) annotationsToAdd = new ArrayList(); Annotation a = decaM.getAnnotationX().getBcelAnnotation(); AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPoolGen(),true); annotationsToAdd.add(ag); mg.addAnnotation(decaM.getAnnotationX()); AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaM.getSourceLocation(),clazz.getName(),mg.getMethod()); reportMethodCtorWeavingMessage(clazz, mg.getMemberView(), decaM,mg.getDeclarationLineNumber()); isChanged = true; modificationOccured = true; unusedDecams.remove(decaM); } else { if (!decaM.isStarredAnnotationPattern()) worthRetrying.add(decaM); } }
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
while (!worthRetrying.isEmpty() && modificationOccured) { modificationOccured = false; List forRemoval = new ArrayList(); for (Iterator iter = worthRetrying.iterator(); iter.hasNext();) { DeclareAnnotation decaM = (DeclareAnnotation) iter.next(); if (decaM.matches(mg.getMemberView(),world)) { if (doesAlreadyHaveAnnotation(mg.getMemberView(),decaM,reportedProblems)) { unusedDecams.remove(decaM); continue; } if (annotationsToAdd==null) annotationsToAdd = new ArrayList(); Annotation a = decaM.getAnnotationX().getBcelAnnotation(); AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPoolGen(),true); annotationsToAdd.add(ag); mg.addAnnotation(decaM.getAnnotationX()); AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaM.getSourceLocation(),clazz.getName(),mg.getMethod()); isChanged = true; modificationOccured = true; forRemoval.add(decaM); unusedDecams.remove(decaM); } } worthRetrying.removeAll(forRemoval);
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
} if (annotationsToAdd!=null) { Method oldMethod = mg.getMethod(); MethodGen myGen = new MethodGen(oldMethod,clazz.getClassName(),clazz.getConstantPoolGen(),false); for (Iterator iter = annotationsToAdd.iterator(); iter.hasNext();) { AnnotationGen a = (AnnotationGen) iter.next(); myGen.addAnnotation(a); } Method newMethod = myGen.getMethod(); members.set(memberCounter,new LazyMethodGen(newMethod,clazz)); } } } checkUnusedDeclareAtTypes(unusedDecams, false); } return isChanged; } private void reportMethodCtorWeavingMessage(LazyClassGen clazz, ResolvedMember member, DeclareAnnotation decaM,int memberLineNumber) { if (!getWorld().getMessageHandler().isIgnoring(IMessage.WEAVEINFO)){ StringBuffer parmString = new StringBuffer("("); UnresolvedType[] paramTypes = member.getParameterTypes(); for (int i = 0; i < paramTypes.length; i++) { UnresolvedType type = paramTypes[i]; String s = org.aspectj.apache.bcel.classfile.Utility.signatureToString(type.getSignature()); if (s.lastIndexOf(".")!=-1) s =s.substring(s.lastIndexOf(".")+1); parmString.append(s); if ((i+1)<paramTypes.length) parmString.append(",");
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
} parmString.append(")"); String methodName = member.getName(); StringBuffer sig = new StringBuffer(); sig.append(org.aspectj.apache.bcel.classfile.Utility.accessToString(member.getModifiers())); sig.append(" "); sig.append(member.getReturnType().toString()); sig.append(" "); sig.append(member.getDeclaringType().toString()); sig.append("."); sig.append(methodName.equals("<init>")?"new":methodName); sig.append(parmString); StringBuffer loc = new StringBuffer(); if (clazz.getFileName()==null) { loc.append("no debug info available"); } else { loc.append(clazz.getFileName()); if (memberLineNumber!=-1) { loc.append(":"+memberLineNumber); } } getWorld().getMessageHandler().handleMessage( WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ANNOTATES, new String[]{ sig.toString(), loc.toString(), decaM.getAnnotationString(), methodName.startsWith("<init>")?"constructor":"method", decaM.getAspect().toString(),
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
Utility.beautifyLocation(decaM.getSourceLocation()) })); } } /** * Looks through a list of declare annotation statements and only returns * those that could possibly match on a field/method/ctor in type. */ private List getMatchingSubset(List declareAnnotations, ResolvedType type) { List subset = new ArrayList(); for (Iterator iter = declareAnnotations.iterator(); iter.hasNext();) { DeclareAnnotation da = (DeclareAnnotation) iter.next(); if (da.couldEverMatch(type)) { subset.add(da); } } return subset; } /** * Get a subset of all the type mungers defined on this aspect */ private List getITDSubset(LazyClassGen clazz,ResolvedTypeMunger.Kind wantedKind) { List subset = new ArrayList(); Collection c = clazz.getBcelObjectType().getTypeMungers(); for (Iterator iter = c.iterator();iter.hasNext();) { BcelTypeMunger typeMunger = (BcelTypeMunger)iter.next(); if (typeMunger.getMunger().getKind()==wantedKind) subset.add(typeMunger);
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
} return subset; } public LazyMethodGen locateAnnotationHolderForFieldMunger(LazyClassGen clazz,BcelTypeMunger fieldMunger) { NewFieldTypeMunger nftm = (NewFieldTypeMunger)fieldMunger.getMunger(); ResolvedMember lookingFor =AjcMemberMaker.interFieldInitializer(nftm.getSignature(),clazz.getType()); List meths = clazz.getMethodGens(); for (Iterator iter = meths.iterator(); iter.hasNext();) { LazyMethodGen element = (LazyMethodGen) iter.next(); if (element.getName().equals(lookingFor.getName())) return element; } return null; } public LazyMethodGen locateAnnotationHolderForMethodCtorMunger(LazyClassGen clazz,BcelTypeMunger methodCtorMunger) { if (methodCtorMunger.getMunger() instanceof NewMethodTypeMunger) { NewMethodTypeMunger nftm = (NewMethodTypeMunger)methodCtorMunger.getMunger(); ResolvedMember lookingFor = AjcMemberMaker.interMethodDispatcher(nftm.getSignature(),methodCtorMunger.getAspectType()); List meths = clazz.getMethodGens(); for (Iterator iter = meths.iterator(); iter.hasNext();) { LazyMethodGen element = (LazyMethodGen) iter.next(); if (element.getName().equals(lookingFor.getName()) && element.getParameterSignature().equals(lookingFor.getParameterSignature())) return element; } return null; } else if (methodCtorMunger.getMunger() instanceof NewConstructorTypeMunger) { NewConstructorTypeMunger nftm = (NewConstructorTypeMunger)methodCtorMunger.getMunger();
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
ResolvedMember lookingFor =AjcMemberMaker.postIntroducedConstructor(methodCtorMunger.getAspectType(),nftm.getSignature().getDeclaringType(),nftm.getSignature().getParameterTypes()); List meths = clazz.getMethodGens(); for (Iterator iter = meths.iterator(); iter.hasNext();) { LazyMethodGen element = (LazyMethodGen) iter.next(); if (element.getName().equals(lookingFor.getName()) && element.getParameterSignature().equals(lookingFor.getParameterSignature())) return element; } return null; } else { throw new RuntimeException("Not sure what this is: "+methodCtorMunger); } } /** * Applies some set of declare @field constructs (List<DeclareAnnotation>) to some bunch * of ITDfields (List<BcelTypeMunger>. It will iterate over the fields repeatedly until * everything has been applied. * */ private boolean weaveAtFieldRepeatedly(List decaFs, List itdFields,List reportedErrors) { boolean isChanged = false; for (Iterator iter = itdFields.iterator(); iter.hasNext();) { BcelTypeMunger fieldMunger = (BcelTypeMunger) iter.next(); ResolvedMember itdIsActually = fieldMunger.getSignature(); List worthRetrying = new ArrayList(); boolean modificationOccured = false; for (Iterator iter2 = decaFs.iterator(); iter2.hasNext();) { DeclareAnnotation decaF = (DeclareAnnotation) iter2.next(); if (decaF.matches(itdIsActually,world)) {
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
LazyMethodGen annotationHolder = locateAnnotationHolderForFieldMunger(clazz,fieldMunger); if (doesAlreadyHaveAnnotation(annotationHolder,itdIsActually,decaF,reportedErrors)) continue; annotationHolder.addAnnotation(decaF.getAnnotationX()); AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),itdIsActually.getSourceLocation()); isChanged = true; modificationOccured = true; } else { if (!decaF.isStarredAnnotationPattern()) worthRetrying.add(decaF); } } while (!worthRetrying.isEmpty() && modificationOccured) { modificationOccured = false; List forRemoval = new ArrayList(); for (Iterator iter2 = worthRetrying.iterator(); iter2.hasNext();) { DeclareAnnotation decaF = (DeclareAnnotation) iter2.next(); if (decaF.matches(itdIsActually,world)) { LazyMethodGen annotationHolder = locateAnnotationHolderForFieldMunger(clazz,fieldMunger); if (doesAlreadyHaveAnnotation(annotationHolder,itdIsActually,decaF,reportedErrors)) continue; annotationHolder.addAnnotation(decaF.getAnnotationX()); AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),itdIsActually.getSourceLocation()); isChanged = true; modificationOccured = true; forRemoval.add(decaF); } worthRetrying.removeAll(forRemoval); } }
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
} return isChanged; } /** * Applies some set of declare @method/@ctor constructs (List<DeclareAnnotation>) to some bunch * of ITDmembers (List<BcelTypeMunger>. It will iterate over the fields repeatedly until * everything has been applied. */ private boolean weaveAtMethodOnITDSRepeatedly(List decaMCs, List itdMethodsCtors,List reportedErrors) { boolean isChanged = false; for (Iterator iter = itdMethodsCtors.iterator(); iter.hasNext();) { BcelTypeMunger methodctorMunger = (BcelTypeMunger) iter.next(); ResolvedMember unMangledInterMethod = methodctorMunger.getSignature(); List worthRetrying = new ArrayList(); boolean modificationOccured = false; for (Iterator iter2 = decaMCs.iterator(); iter2.hasNext();) { DeclareAnnotation decaMC = (DeclareAnnotation) iter2.next(); if (decaMC.matches(unMangledInterMethod,world)) { LazyMethodGen annotationHolder = locateAnnotationHolderForMethodCtorMunger(clazz,methodctorMunger); if (annotationHolder == null || doesAlreadyHaveAnnotation(annotationHolder,unMangledInterMethod,decaMC,reportedErrors)){ continue; } annotationHolder.addAnnotation(decaMC.getAnnotationX()); isChanged=true; AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaMC.getSourceLocation(),unMangledInterMethod.getSourceLocation()); reportMethodCtorWeavingMessage(clazz, unMangledInterMethod, decaMC,-1); modificationOccured = true;
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
} else { if (!decaMC.isStarredAnnotationPattern()) worthRetrying.add(decaMC); } } while (!worthRetrying.isEmpty() && modificationOccured) { modificationOccured = false; List forRemoval = new ArrayList(); for (Iterator iter2 = worthRetrying.iterator(); iter2.hasNext();) { DeclareAnnotation decaMC = (DeclareAnnotation) iter2.next(); if (decaMC.matches(unMangledInterMethod,world)) { LazyMethodGen annotationHolder = locateAnnotationHolderForFieldMunger(clazz,methodctorMunger); if (doesAlreadyHaveAnnotation(annotationHolder,unMangledInterMethod,decaMC,reportedErrors)) continue; annotationHolder.addAnnotation(decaMC.getAnnotationX()); unMangledInterMethod.addAnnotation(decaMC.getAnnotationX()); AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaMC.getSourceLocation(),unMangledInterMethod.getSourceLocation()); isChanged = true; modificationOccured = true; forRemoval.add(decaMC); } worthRetrying.removeAll(forRemoval); } } } return isChanged; } private boolean dontAddTwice(DeclareAnnotation decaF, Annotation [] dontAddMeTwice){ for (int i = 0; i < dontAddMeTwice.length; i++){
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
Annotation ann = dontAddMeTwice[i]; if (ann != null && decaF.getAnnotationX().getTypeName().equals(ann.getTypeName())){ return true; } } return false; } /** * Weave any declare @field statements into the fields of the supplied class * * Interesting case relating to public ITDd fields. The annotations are really stored against * the interfieldinit method in the aspect, but the public field is placed in the target * type and then is processed in the 2nd pass over fields that occurs. I think it would be * more expensive to avoid putting the annotation on that inserted public field than just to * have it put there as well as on the interfieldinit method. */ private boolean weaveDeclareAtField(LazyClassGen clazz) { List reportedProblems = new ArrayList(); List allDecafs = world.getDeclareAnnotationOnFields(); if (allDecafs.isEmpty()) return false;
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
boolean isChanged = false; List itdFields = getITDSubset(clazz,ResolvedTypeMunger.Field); if (itdFields!=null) { isChanged = weaveAtFieldRepeatedly(allDecafs,itdFields,reportedProblems); } List decaFs = getMatchingSubset(allDecafs,clazz.getType()); if (decaFs.isEmpty()) return false; Field[] fields = clazz.getFieldGens(); if (fields!=null) { Set unusedDecafs = new HashSet(); unusedDecafs.addAll(decaFs); for (int fieldCounter = 0;fieldCounter<fields.length;fieldCounter++) { BcelField aBcelField = new BcelField(clazz.getBcelObjectType(),fields[fieldCounter]); if (!aBcelField.getName().startsWith(NameMangler.PREFIX)) { List worthRetrying = new ArrayList(); boolean modificationOccured = false; Annotation [] dontAddMeTwice = fields[fieldCounter].getAnnotations(); for (Iterator iter = decaFs.iterator(); iter.hasNext();) { DeclareAnnotation decaF = (DeclareAnnotation) iter.next(); if (decaF.matches(aBcelField,world)) { if (!dontAddTwice(decaF,dontAddMeTwice)){ if (doesAlreadyHaveAnnotation(aBcelField,decaF,reportedProblems)){
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
unusedDecafs.remove(decaF); continue; } if(decaF.getAnnotationX().isRuntimeVisible()){ Annotation a = decaF.getAnnotationX().getBcelAnnotation(); AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPoolGen(),true); FieldGen myGen = new FieldGen(fields[fieldCounter],clazz.getConstantPoolGen()); myGen.addAnnotation(ag); Field newField = myGen.getField(); aBcelField.addAnnotation(decaF.getAnnotationX()); clazz.replaceField(fields[fieldCounter],newField); fields[fieldCounter]=newField; } else{ aBcelField.addAnnotation(decaF.getAnnotationX()); } } AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),clazz.getName(),fields[fieldCounter]); reportFieldAnnotationWeavingMessage(clazz, fields, fieldCounter, decaF); isChanged = true; modificationOccured = true; unusedDecafs.remove(decaF);
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
} else { if (!decaF.isStarredAnnotationPattern()) worthRetrying.add(decaF); } } while (!worthRetrying.isEmpty() && modificationOccured) { modificationOccured = false; List forRemoval = new ArrayList(); for (Iterator iter = worthRetrying.iterator(); iter.hasNext();) { DeclareAnnotation decaF = (DeclareAnnotation) iter.next(); if (decaF.matches(aBcelField,world)) { if (doesAlreadyHaveAnnotation(aBcelField,decaF,reportedProblems)) { unusedDecafs.remove(decaF); continue; } aBcelField.addAnnotation(decaF.getAnnotationX()); AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),clazz.getName(),fields[fieldCounter]); isChanged = true; modificationOccured = true; forRemoval.add(decaF); unusedDecafs.remove(decaF); } }
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
worthRetrying.removeAll(forRemoval); } } } checkUnusedDeclareAtTypes(unusedDecafs,true); } return isChanged; } /** * Report an error if the reason a "declare @method/ctor/field" was not used was because the member * specified does not exist. This method is passed some set of declare statements that didn't * match and a flag indicating whether the set contains declare @field or declare @method/ctor * entries. */ private void checkUnusedDeclareAtTypes(Set unusedDecaTs, boolean isDeclareAtField) { for (Iterator iter = unusedDecaTs.iterator(); iter.hasNext();) { DeclareAnnotation declA = (DeclareAnnotation) iter.next(); if ((declA.isExactPattern() || (declA.getSignaturePattern().getDeclaringType() instanceof ExactTypePattern)) && (!declA.getSignaturePattern().getName().isAny() || (declA.getKind() == DeclareAnnotation.AT_CONSTRUCTOR))) { boolean itdMatch = false; List lst = clazz.getType().getInterTypeMungers(); for (Iterator iterator = lst.iterator(); iterator.hasNext() && !itdMatch;) { BcelTypeMunger element = (BcelTypeMunger) iterator.next();
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
if (element.getMunger() instanceof NewFieldTypeMunger) { NewFieldTypeMunger nftm = (NewFieldTypeMunger)element.getMunger(); itdMatch = declA.getSignaturePattern().matches(nftm.getSignature(),world,false); }else if (element.getMunger() instanceof NewMethodTypeMunger) { NewMethodTypeMunger nmtm = (NewMethodTypeMunger)element.getMunger(); itdMatch = declA.getSignaturePattern().matches(nmtm.getSignature(),world,false); } else if (element.getMunger() instanceof NewConstructorTypeMunger) { NewConstructorTypeMunger nctm = (NewConstructorTypeMunger)element.getMunger(); itdMatch = declA.getSignaturePattern().matches(nctm.getSignature(),world,false); } } if (!itdMatch) { IMessage message = null; if (isDeclareAtField) { message = new Message( "The field '"+ declA.getSignaturePattern().toString() + "' does not exist", declA.getSourceLocation() , true); } else { message = new Message( "The method '"+ declA.getSignaturePattern().toString() + "' does not exist", declA.getSourceLocation() , true); } world.getMessageHandler().handleMessage(message); } } } } private void reportFieldAnnotationWeavingMessage(LazyClassGen clazz, Field[] fields, int fieldCounter, DeclareAnnotation decaF) {
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
if (!getWorld().getMessageHandler().isIgnoring(IMessage.WEAVEINFO)){ Field theField = fields[fieldCounter]; world.getMessageHandler().handleMessage( WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ANNOTATES, new String[]{ theField.toString() + "' of type '" + clazz.getName(), clazz.getFileName(), decaF.getAnnotationString(), "field", decaF.getAspect().toString(), Utility.beautifyLocation(decaF.getSourceLocation())})); } } /** * Check if a resolved member (field/method/ctor) already has an annotation, if it * does then put out a warning and return true */ private boolean doesAlreadyHaveAnnotation(ResolvedMember rm,DeclareAnnotation deca,List reportedProblems) { if (rm.hasAnnotation(deca.getAnnotationTypeX())) { if (world.getLint().elementAlreadyAnnotated.isEnabled()) { Integer uniqueID = new Integer(rm.hashCode()*deca.hashCode()); if (!reportedProblems.contains(uniqueID)) { reportedProblems.add(uniqueID); world.getLint().elementAlreadyAnnotated.signal( new String[]{rm.toString(),deca.getAnnotationTypeX().toString()}, rm.getSourceLocation(),new ISourceLocation[]{deca.getSourceLocation()}); } } return true;
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
} return false; } private boolean doesAlreadyHaveAnnotation(LazyMethodGen rm,ResolvedMember itdfieldsig,DeclareAnnotation deca,List reportedProblems) { if (rm != null && rm.hasAnnotation(deca.getAnnotationTypeX())) { if (world.getLint().elementAlreadyAnnotated.isEnabled()) { Integer uniqueID = new Integer(rm.hashCode()*deca.hashCode()); if (!reportedProblems.contains(uniqueID)) { reportedProblems.add(uniqueID); reportedProblems.add(new Integer(itdfieldsig.hashCode()*deca.hashCode())); world.getLint().elementAlreadyAnnotated.signal( new String[]{itdfieldsig.toString(),deca.getAnnotationTypeX().toString()}, rm.getSourceLocation(),new ISourceLocation[]{deca.getSourceLocation()}); } } return true; } return false; } private Set findAspectsForMungers(LazyMethodGen mg) { Set aspectsAffectingType = new HashSet(); for (Iterator iter = mg.matchedShadows.iterator(); iter.hasNext();) { BcelShadow aShadow = (BcelShadow) iter.next(); for (Iterator iter2 = aShadow.getMungers().iterator();iter2.hasNext();) { ShadowMunger aMunger = (ShadowMunger) iter2.next(); if (aMunger instanceof BcelAdvice) { BcelAdvice bAdvice = (BcelAdvice)aMunger;
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
if(bAdvice.getConcreteAspect() != null){ aspectsAffectingType.add(bAdvice.getConcreteAspect().getName()); } } else { } } } return aspectsAffectingType; } private boolean inlineSelfConstructors(List methodGens) { boolean inlinedSomething = false; for (Iterator i = methodGens.iterator(); i.hasNext();) { LazyMethodGen mg = (LazyMethodGen) i.next(); if (! mg.getName().equals("<init>")) continue; InstructionHandle ih = findSuperOrThisCall(mg); if (ih != null && isThisCall(ih)) { LazyMethodGen donor = getCalledMethod(ih); inlineMethod(donor, mg, ih); inlinedSomething = true; } } return inlinedSomething; } private void positionAndImplement(List initializationShadows) { for (Iterator i = initializationShadows.iterator(); i.hasNext(); ) { BcelShadow s = (BcelShadow) i.next(); positionInitializationShadow(s); s.implement();
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
} } private void positionInitializationShadow(BcelShadow s) { LazyMethodGen mg = s.getEnclosingMethod(); InstructionHandle call = findSuperOrThisCall(mg); InstructionList body = mg.getBody(); ShadowRange r = new ShadowRange(body); r.associateWithShadow((BcelShadow) s); if (s.getKind() == Shadow.PreInitialization) { r.associateWithTargets( Range.genStart(body, body.getStart().getNext()), Range.genEnd(body, call.getPrev())); } else { r.associateWithTargets( Range.genStart(body, call.getNext()), Range.genEnd(body)); } } private boolean isThisCall(InstructionHandle ih) { INVOKESPECIAL inst = (INVOKESPECIAL) ih.getInstruction(); return inst.getClassName(cpg).equals(clazz.getName()); } /** inline a particular call in bytecode. * * @param donor the method we want to inline * @param recipient the method containing the call we want to inline
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
* @param call the instructionHandle in recipient's body holding the call we want to * inline. */ public static void inlineMethod( LazyMethodGen donor, LazyMethodGen recipient, InstructionHandle call) { /* Implementation notes: * * We allocate two slots for every tempvar so we don't screw up * longs and doubles which may share space. This could be conservatively avoided * (no reference to a long/double instruction, don't do it) or packed later. * Right now we don't bother to pack. * * Allocate a new var for each formal param of the inlined. Fill with stack * contents. Then copy the inlined instructions in with the appropriate remap * table. Any framelocs used by locals in inlined are reallocated to top of * frame, */ final InstructionFactory fact = recipient.getEnclosingClass().getFactory(); IntMap frameEnv = new IntMap(); InstructionList argumentStores = genArgumentStores(donor, recipient, frameEnv, fact); InstructionList inlineInstructions = genInlineInstructions(donor, recipient, frameEnv, fact, false); inlineInstructions.insert(argumentStores);
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
recipient.getBody().append(call, inlineInstructions); Utility.deleteInstruction(call, recipient); } } /** * Input method is a synchronized method, we remove the bit flag for synchronized and * then insert a try..finally block * * Some jumping through firey hoops required - depending on the input code level (1.5 or not) * we may or may not be able to use the LDC instruction that takes a class literal (doesnt on * <1.5). * * FIXME asc Before promoting -Xjoinpoints:synchronization to be a standard option, this needs a bunch of * tidying up - there is some duplication that can be removed. */ public static void transformSynchronizedMethod(LazyMethodGen synchronizedMethod) { if (trace.isTraceEnabled()) trace.enter("transformSynchronizedMethod",synchronizedMethod); final InstructionFactory fact = synchronizedMethod.getEnclosingClass().getFactory(); InstructionList body = synchronizedMethod.getBody(); InstructionList prepend = new InstructionList(); Type enclosingClassType = BcelWorld.makeBcelType(synchronizedMethod.getEnclosingClass().getType()); Type javaLangClassType = Type.getType(Class.class);
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
if (synchronizedMethod.isStatic()) { if (synchronizedMethod.getEnclosingClass().isAtLeastJava5()) { int slotForLockObject = synchronizedMethod.allocateLocal(enclosingClassType); prepend.append(fact.createConstant(enclosingClassType)); prepend.append(InstructionFactory.createDup(1)); prepend.append(InstructionFactory.createStore(enclosingClassType, slotForLockObject)); prepend.append(InstructionFactory.MONITORENTER); InstructionList finallyBlock = new InstructionList(); finallyBlock.append(InstructionFactory.createLoad(Type.getType(java.lang.Class.class),slotForLockObject));
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
finallyBlock.append(InstructionConstants.MONITOREXIT); finallyBlock.append(InstructionConstants.ATHROW); InstructionHandle walker = body.getStart(); List rets = new ArrayList(); while (walker!=null) { if (walker.getInstruction() instanceof ReturnInstruction) { rets.add(walker); } walker = walker.getNext(); } if (rets.size()>0) { for (Iterator iter = rets.iterator(); iter.hasNext();) { InstructionHandle element = (InstructionHandle) iter.next(); InstructionList monitorExitBlock = new InstructionList(); monitorExitBlock.append(InstructionFactory.createLoad(enclosingClassType,slotForLockObject)); monitorExitBlock.append(InstructionConstants.MONITOREXIT); InstructionHandle monitorExitBlockStart = body.insert(element,monitorExitBlock); InstructionTargeter[] targeters = element.getTargeters(); if (targeters!=null) { for (int i = 0; i < targeters.length; i++) {
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
InstructionTargeter targeter = targeters[i]; if (targeter instanceof LocalVariableTag) { } else if (targeter instanceof LineNumberTag) { } else if (targeter instanceof GOTO || targeter instanceof GOTO_W) { targeter.updateTarget(element, monitorExitBlockStart); } else if (targeter instanceof BranchInstruction) { targeter.updateTarget(element, monitorExitBlockStart); } else { throw new RuntimeException("Unexpected targeter encountered during transform: "+targeter); } } } } } InstructionHandle finallyStart = finallyBlock.getStart(); InstructionHandle tryPosition = body.getStart(); InstructionHandle catchPosition = body.getEnd(); body.insert(body.getStart(),prepend); synchronizedMethod.getBody().append(finallyBlock); synchronizedMethod.addExceptionHandler(tryPosition, catchPosition,finallyStart,null,false); synchronizedMethod.addExceptionHandler(finallyStart,finallyStart.getNext(),finallyStart,null,false); } else {
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
Type classType = BcelWorld.makeBcelType(synchronizedMethod.getEnclosingClass().getType()); Type clazzType = Type.getType(Class.class); InstructionList parttwo = new InstructionList(); parttwo.append(InstructionFactory.createDup(1)); int slotForThis = synchronizedMethod.allocateLocal(classType); parttwo.append(InstructionFactory.createStore(clazzType, slotForThis)); parttwo.append(InstructionFactory.MONITORENTER); String fieldname = synchronizedMethod.getEnclosingClass().allocateField("class$"); Field f = new FieldGen(Modifier.STATIC | Modifier.PRIVATE, Type.getType(Class.class),fieldname,synchronizedMethod.getEnclosingClass().getConstantPoolGen()).getField(); synchronizedMethod.getEnclosingClass().addField(f, null); String name = synchronizedMethod.getEnclosingClass().getName(); prepend.append(fact.createGetStatic(name, fieldname, Type.getType(Class.class))); prepend.append(InstructionFactory.createDup(1)); prepend.append(InstructionFactory.createBranchInstruction(Constants.IFNONNULL, parttwo.getStart())); prepend.append(InstructionFactory.POP); prepend.append(fact.createConstant(name)); InstructionHandle tryInstruction = prepend.getEnd(); prepend.append(fact.createInvoke("java.lang.Class", "forName", clazzType,new Type[]{ Type.getType(String.class)}, Constants.INVOKESTATIC));
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
InstructionHandle catchInstruction = prepend.getEnd(); prepend.append(InstructionFactory.createDup(1)); prepend.append(fact.createPutStatic(synchronizedMethod.getEnclosingClass().getType().getName(), fieldname, Type.getType(Class.class))); prepend.append(InstructionFactory.createBranchInstruction(Constants.GOTO, parttwo.getStart())); InstructionList catchBlockForLiteralLoadingFail = new InstructionList(); catchBlockForLiteralLoadingFail.append(fact.createNew((ObjectType)Type.getType(NoClassDefFoundError.class))); catchBlockForLiteralLoadingFail.append(InstructionFactory.createDup_1(1)); catchBlockForLiteralLoadingFail.append(InstructionFactory.SWAP); catchBlockForLiteralLoadingFail.append(fact.createInvoke("java.lang.Throwable", "getMessage", Type.getType(String.class),new Type[]{}, Constants.INVOKEVIRTUAL)); catchBlockForLiteralLoadingFail.append(fact.createInvoke("java.lang.NoClassDefFoundError", "<init>", Type.VOID,new Type[]{ Type.getType(String.class)}, Constants.INVOKESPECIAL)); catchBlockForLiteralLoadingFail.append(InstructionFactory.ATHROW); InstructionHandle catchBlockStart = catchBlockForLiteralLoadingFail.getStart(); prepend.append(catchBlockForLiteralLoadingFail); prepend.append(parttwo);
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
InstructionList finallyBlock = new InstructionList(); finallyBlock.append(InstructionFactory.createLoad(Type.getType(java.lang.Class.class),slotForThis)); finallyBlock.append(InstructionConstants.MONITOREXIT); finallyBlock.append(InstructionConstants.ATHROW); InstructionHandle walker = body.getStart(); List rets = new ArrayList(); while (walker!=null) { if (walker.getInstruction() instanceof ReturnInstruction) { rets.add(walker); } walker = walker.getNext(); } if (rets.size()>0) { for (Iterator iter = rets.iterator(); iter.hasNext();) { InstructionHandle element = (InstructionHandle) iter.next(); InstructionList monitorExitBlock = new InstructionList(); monitorExitBlock.append(InstructionFactory.createLoad(classType,slotForThis)); monitorExitBlock.append(InstructionConstants.MONITOREXIT); InstructionHandle monitorExitBlockStart = body.insert(element,monitorExitBlock);
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
InstructionTargeter[] targeters = element.getTargeters(); if (targeters!=null) { for (int i = 0; i < targeters.length; i++) { InstructionTargeter targeter = targeters[i]; if (targeter instanceof LocalVariableTag) { } else if (targeter instanceof LineNumberTag) { } else if (targeter instanceof GOTO || targeter instanceof GOTO_W) { targeter.updateTarget(element, monitorExitBlockStart); } else if (targeter instanceof BranchInstruction) { targeter.updateTarget(element, monitorExitBlockStart); } else { throw new RuntimeException("Unexpected targeter encountered during transform: "+targeter); } } } } } InstructionHandle finallyStart = finallyBlock.getStart(); InstructionHandle tryPosition = body.getStart(); InstructionHandle catchPosition = body.getEnd();
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
body.insert(body.getStart(),prepend); synchronizedMethod.getBody().append(finallyBlock); synchronizedMethod.addExceptionHandler(tryPosition, catchPosition,finallyStart,null,false); synchronizedMethod.addExceptionHandler(tryInstruction, catchInstruction,catchBlockStart,(ObjectType)Type.getType(ClassNotFoundException.class),true); synchronizedMethod.addExceptionHandler(finallyStart,finallyStart.getNext(),finallyStart,null,false); } } else { Type classType = BcelWorld.makeBcelType(synchronizedMethod.getEnclosingClass().getType()); prepend.append(InstructionFactory.createLoad(classType,0)); prepend.append(InstructionFactory.createDup(1)); int slotForThis = synchronizedMethod.allocateLocal(classType); prepend.append(InstructionFactory.createStore(classType, slotForThis)); prepend.append(InstructionFactory.MONITORENTER);
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
InstructionList finallyBlock = new InstructionList(); finallyBlock.append(InstructionFactory.createLoad(classType,slotForThis)); finallyBlock.append(InstructionConstants.MONITOREXIT); finallyBlock.append(InstructionConstants.ATHROW); InstructionHandle walker = body.getStart(); List rets = new ArrayList(); while (walker!=null) { if (walker.getInstruction() instanceof ReturnInstruction) { rets.add(walker); } walker = walker.getNext(); } if (rets.size()>0) { for (Iterator iter = rets.iterator(); iter.hasNext();) { InstructionHandle element = (InstructionHandle) iter.next(); InstructionList monitorExitBlock = new InstructionList(); monitorExitBlock.append(InstructionFactory.createLoad(classType,slotForThis)); monitorExitBlock.append(InstructionConstants.MONITOREXIT); InstructionHandle monitorExitBlockStart = body.insert(element,monitorExitBlock);
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
InstructionTargeter[] targeters = element.getTargeters(); if (targeters!=null) { for (int i = 0; i < targeters.length; i++) { InstructionTargeter targeter = targeters[i]; if (targeter instanceof LocalVariableTag) { } else if (targeter instanceof LineNumberTag) { } else if (targeter instanceof GOTO || targeter instanceof GOTO_W) { targeter.updateTarget(element, monitorExitBlockStart); } else if (targeter instanceof BranchInstruction) { targeter.updateTarget(element, monitorExitBlockStart); } else { throw new RuntimeException("Unexpected targeter encountered during transform: "+targeter); } } } } } InstructionHandle finallyStart = finallyBlock.getStart(); InstructionHandle tryPosition = body.getStart(); InstructionHandle catchPosition = body.getEnd(); body.insert(body.getStart(),prepend); synchronizedMethod.getBody().append(finallyBlock);
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
synchronizedMethod.addExceptionHandler(tryPosition, catchPosition,finallyStart,null,false); synchronizedMethod.addExceptionHandler(finallyStart,finallyStart.getNext(),finallyStart,null,false); } if (trace.isTraceEnabled()) trace.exit("transformSynchronizedMethod"); } /** generate the instructions to be inlined. * * @param donor the method from which we will copy (and adjust frame and jumps) * instructions. * @param recipient the method the instructions will go into. Used to get the frame * size so we can allocate new frame locations for locals in donor. * @param frameEnv an environment to map from donor frame to recipient frame, * initially populated with argument locations. * @param fact an instruction factory for recipient */ static InstructionList genInlineInstructions( LazyMethodGen donor, LazyMethodGen recipient, IntMap frameEnv, InstructionFactory fact, boolean keepReturns)
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
{ InstructionList footer = new InstructionList(); InstructionHandle end = footer.append(InstructionConstants.NOP); InstructionList ret = new InstructionList(); InstructionList sourceList = donor.getBody(); Map srcToDest = new HashMap(); ConstantPoolGen donorCpg = donor.getEnclosingClass().getConstantPoolGen(); ConstantPoolGen recipientCpg = recipient.getEnclosingClass().getConstantPoolGen(); boolean isAcrossClass = donorCpg != recipientCpg; for (InstructionHandle src = sourceList.getStart(); src != null; src = src.getNext()) { Instruction fresh = Utility.copyInstruction(src.getInstruction()); InstructionHandle dest; if (fresh instanceof CPInstruction) { if (isAcrossClass) { CPInstruction cpi = (CPInstruction) fresh; cpi.setIndex( recipientCpg.addConstant( donorCpg.getConstant(cpi.getIndex()), donorCpg)); } }
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
if (src.getInstruction() == Range.RANGEINSTRUCTION) { dest = ret.append(Range.RANGEINSTRUCTION); } else if (fresh instanceof ReturnInstruction) { if (keepReturns) { dest = ret.append(fresh); } else { dest = ret.append(InstructionFactory.createBranchInstruction(Constants.GOTO, end)); } } else if (fresh instanceof BranchInstruction) { dest = ret.append((BranchInstruction) fresh); } else if ( fresh instanceof LocalVariableInstruction || fresh instanceof RET) { IndexedInstruction indexed = (IndexedInstruction) fresh; int oldIndex = indexed.getIndex(); int freshIndex; if (!frameEnv.hasKey(oldIndex)) { freshIndex = recipient.allocateLocal(2); frameEnv.put(oldIndex, freshIndex); } else { freshIndex = frameEnv.get(oldIndex); } indexed.setIndex(freshIndex); dest = ret.append(fresh); } else { dest = ret.append(fresh); } srcToDest.put(src, dest); }
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
Map tagMap = new HashMap(); Map shadowMap = new HashMap(); for (InstructionHandle dest = ret.getStart(), src = sourceList.getStart(); dest != null; dest = dest.getNext(), src = src.getNext()) { Instruction inst = dest.getInstruction(); if (inst instanceof BranchInstruction) { BranchInstruction branch = (BranchInstruction) inst; InstructionHandle oldTarget = branch.getTarget(); InstructionHandle newTarget = (InstructionHandle) srcToDest.get(oldTarget); if (newTarget == null) { } else { branch.setTarget(newTarget); if (branch instanceof Select) { Select select = (Select) branch; InstructionHandle[] oldTargets = select.getTargets(); for (int k = oldTargets.length - 1; k >= 0; k--) { select.setTarget( k, (InstructionHandle) srcToDest.get(oldTargets[k])); } } } }
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
InstructionTargeter[] srcTargeters = src.getTargeters(); if (srcTargeters != null) { for (int j = srcTargeters.length - 1; j >= 0; j--) { InstructionTargeter old = srcTargeters[j]; if (old instanceof Tag) { Tag oldTag = (Tag) old; Tag fresh = (Tag) tagMap.get(oldTag); if (fresh == null) { fresh = oldTag.copy(); tagMap.put(oldTag, fresh); } dest.addTargeter(fresh); } else if (old instanceof ExceptionRange) { ExceptionRange er = (ExceptionRange) old; if (er.getStart() == src) { ExceptionRange freshEr = new ExceptionRange( recipient.getBody(), er.getCatchType(), er.getPriority()); freshEr.associateWithTargets( dest, (InstructionHandle)srcToDest.get(er.getEnd()), (InstructionHandle)srcToDest.get(er.getHandler())); } } else if (old instanceof ShadowRange) { ShadowRange oldRange = (ShadowRange) old; if (oldRange.getStart() == src) {
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
BcelShadow oldShadow = oldRange.getShadow(); BcelShadow freshEnclosing = oldShadow.getEnclosingShadow() == null ? null : (BcelShadow) shadowMap.get(oldShadow.getEnclosingShadow()); BcelShadow freshShadow = oldShadow.copyInto(recipient, freshEnclosing); ShadowRange freshRange = new ShadowRange(recipient.getBody()); freshRange.associateWithShadow(freshShadow); freshRange.associateWithTargets( dest, (InstructionHandle) srcToDest.get(oldRange.getEnd())); shadowMap.put(oldRange, freshRange); } } } } } if (!keepReturns) ret.append(footer); return ret; } static InstructionList rewriteWithMonitorExitCalls(InstructionList sourceList,InstructionFactory fact,boolean keepReturns,int monitorVarSlot,Type monitorVarType) { InstructionList footer = new InstructionList(); InstructionHandle end = footer.append(InstructionConstants.NOP);
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
InstructionList newList = new InstructionList(); Map srcToDest = new HashMap(); for (InstructionHandle src = sourceList.getStart(); src != null; src = src.getNext()) { Instruction fresh = Utility.copyInstruction(src.getInstruction()); InstructionHandle dest; if (src.getInstruction() == Range.RANGEINSTRUCTION) { dest = newList.append(Range.RANGEINSTRUCTION); } else if (fresh instanceof ReturnInstruction) { if (keepReturns) { newList.append(InstructionFactory.createLoad(monitorVarType,monitorVarSlot)); newList.append(InstructionConstants.MONITOREXIT); dest = newList.append(fresh); } else { dest = newList.append(InstructionFactory.createBranchInstruction(Constants.GOTO, end)); } } else if (fresh instanceof BranchInstruction) { dest = newList.append((BranchInstruction) fresh); } else if ( fresh instanceof LocalVariableInstruction || fresh instanceof RET) { IndexedInstruction indexed = (IndexedInstruction) fresh; int oldIndex = indexed.getIndex(); int freshIndex; freshIndex = oldIndex; indexed.setIndex(freshIndex); dest = newList.append(fresh); } else {
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
dest = newList.append(fresh); } srcToDest.put(src, dest); } Map tagMap = new HashMap(); Map shadowMap = new HashMap(); for (InstructionHandle dest = newList.getStart(), src = sourceList.getStart(); dest != null; dest = dest.getNext(), src = src.getNext()) { Instruction inst = dest.getInstruction(); if (inst instanceof BranchInstruction) { BranchInstruction branch = (BranchInstruction) inst; InstructionHandle oldTarget = branch.getTarget(); InstructionHandle newTarget = (InstructionHandle) srcToDest.get(oldTarget); if (newTarget == null) { } else { branch.setTarget(newTarget); if (branch instanceof Select) { Select select = (Select) branch; InstructionHandle[] oldTargets = select.getTargets(); for (int k = oldTargets.length - 1; k >= 0; k--) { select.setTarget( k,
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
(InstructionHandle) srcToDest.get(oldTargets[k])); } } } } InstructionTargeter[] srcTargeters = src.getTargeters(); if (srcTargeters != null) { for (int j = srcTargeters.length - 1; j >= 0; j--) { InstructionTargeter old = srcTargeters[j]; if (old instanceof Tag) { Tag oldTag = (Tag) old; Tag fresh = (Tag) tagMap.get(oldTag); if (fresh == null) { fresh = oldTag.copy(); tagMap.put(oldTag, fresh); } dest.addTargeter(fresh); } else if (old instanceof ExceptionRange) { ExceptionRange er = (ExceptionRange) old; if (er.getStart() == src) { ExceptionRange freshEr = new ExceptionRange(newList,er.getCatchType(),er.getPriority()); freshEr.associateWithTargets( dest, (InstructionHandle)srcToDest.get(er.getEnd()), (InstructionHandle)srcToDest.get(er.getHandler())); } }
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
/*else if (old instanceof ShadowRange) { ShadowRange oldRange = (ShadowRange) old; if (oldRange.getStart() == src) { BcelShadow oldShadow = oldRange.getShadow(); BcelShadow freshEnclosing = oldShadow.getEnclosingShadow() == null ? null : (BcelShadow) shadowMap.get(oldShadow.getEnclosingShadow()); BcelShadow freshShadow = oldShadow.copyInto(recipient, freshEnclosing); ShadowRange freshRange = new ShadowRange(recipient.getBody()); freshRange.associateWithShadow(freshShadow); freshRange.associateWithTargets( dest, (InstructionHandle) srcToDest.get(oldRange.getEnd())); shadowMap.put(oldRange, freshRange); } }*/ } } } if (!keepReturns) newList.append(footer); return newList; } /** generate the argument stores in preparation for inlining.
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
* * @param donor the method we will inline from. Used to get the signature. * @param recipient the method we will inline into. Used to get the frame size * so we can allocate fresh locations. * @param frameEnv an empty environment we populate with a map from donor frame to * recipient frame. * @param fact an instruction factory for recipient */ private static InstructionList genArgumentStores( LazyMethodGen donor, LazyMethodGen recipient, IntMap frameEnv, InstructionFactory fact) { InstructionList ret = new InstructionList(); int donorFramePos = 0; if (! donor.isStatic()) { int targetSlot = recipient.allocateLocal(Type.OBJECT); ret.insert(InstructionFactory.createStore(Type.OBJECT, targetSlot)); frameEnv.put(donorFramePos, targetSlot); donorFramePos += 1; } Type[] argTypes = donor.getArgumentTypes(); for (int i = 0, len = argTypes.length; i < len; i++) { Type argType = argTypes[i]; int argSlot = recipient.allocateLocal(argType); ret.insert(InstructionFactory.createStore(argType, argSlot)); frameEnv.put(donorFramePos, argSlot); donorFramePos += argType.getSize();
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
} return ret; } /** get a called method: Assumes the called method is in this class, * and the reference to it is exact (a la INVOKESPECIAL). * * @param ih The InvokeInstruction instructionHandle pointing to the called method. */ private LazyMethodGen getCalledMethod( InstructionHandle ih) { InvokeInstruction inst = (InvokeInstruction) ih.getInstruction(); String methodName = inst.getName(cpg); String signature = inst.getSignature(cpg); return clazz.getLazyMethodGen(methodName, signature); } private void weaveInAddedMethods() { Collections.sort(addedLazyMethodGens, new Comparator() { public int compare(Object a, Object b) { LazyMethodGen aa = (LazyMethodGen) a; LazyMethodGen bb = (LazyMethodGen) b; int i = aa.getName().compareTo(bb.getName()); if (i != 0) return i; return aa.getSignature().compareTo(bb.getSignature()); } } ); for (Iterator i = addedLazyMethodGens.iterator(); i.hasNext(); ) {
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
clazz.addMethodGen((LazyMethodGen)i.next()); } } void addPerSingletonField(Member field) { ObjectType aspectType = (ObjectType) BcelWorld.makeBcelType(field.getReturnType()); String aspectName = field.getReturnType().getName(); LazyMethodGen clinit = clazz.getStaticInitializer(); InstructionList setup = new InstructionList(); InstructionFactory fact = clazz.getFactory(); setup.append(fact.createNew(aspectType)); setup.append(InstructionFactory.createDup(1)); setup.append(fact.createInvoke( aspectName, "<init>", Type.VOID, new Type[0], Constants.INVOKESPECIAL)); setup.append( fact.createFieldAccess( aspectName, field.getName(), aspectType, Constants.PUTSTATIC)); clinit.getBody().insert(setup); } /** * Returns null if this is not a Java constructor, and then we won't * weave into it at all */ private InstructionHandle findSuperOrThisCall(LazyMethodGen mg) {
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
int depth = 1; InstructionHandle start = mg.getBody().getStart(); while (true) { if (start == null) return null; Instruction inst = start.getInstruction(); if (inst instanceof INVOKESPECIAL && ((INVOKESPECIAL) inst).getName(cpg).equals("<init>")) { depth--; if (depth == 0) return start; } else if (inst instanceof NEW) { depth++; } start = start.getNext(); } } private boolean match(LazyMethodGen mg) { BcelShadow enclosingShadow; List shadowAccumulator = new ArrayList(); boolean startsAngly = mg.getName().charAt(0)=='<'; if (startsAngly && mg.getName().equals("<init>")) { return matchInit(mg, shadowAccumulator); } else if (!shouldWeaveBody(mg)) { return false; } else { if (startsAngly && mg.getName().equals("<clinit>")) {
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
clinitShadow = enclosingShadow = BcelShadow.makeStaticInitialization(world, mg); } else if (mg.isAdviceMethod()) { enclosingShadow = BcelShadow.makeAdviceExecution(world, mg); } else { AjAttribute.EffectiveSignatureAttribute effective = mg.getEffectiveSignature(); if (effective == null) { enclosingShadow = BcelShadow.makeMethodExecution(world, mg, !canMatchBodyShadows); } else if (effective.isWeaveBody()) { ResolvedMember rm = effective.getEffectiveSignature(); fixAnnotationsForResolvedMember(rm,mg.getMemberView()); enclosingShadow = BcelShadow.makeShadowForMethod(world,mg,effective.getShadowKind(),rm); } else { return false; } } if (canMatchBodyShadows) { for (InstructionHandle h = mg.getBody().getStart(); h != null; h = h.getNext()) { match(mg, h, enclosingShadow, shadowAccumulator); } }
230,817
Bug 230817 LazyMethodGen.remap() NullPointerException
This has been reported a few times by different users, but has always proved tough to diagnose. The typical stack trace is something like: java.lang.NullPointerException org.aspectj.weaver.bcel.LazyMethodGen.remap(LazyMethodGen.java:1237) org.aspectj.weaver.bcel.LazyMethodGen.addExceptionHandlers(LazyMethodGen.java:1132) org.aspectj.weaver.bcel.LazyMethodGen.packBody(LazyMethodGen.java:1078) org.aspectj.weaver.bcel.LazyMethodGen.pack(LazyMethodGen.java:977) org.aspectj.weaver.bcel.LazyMethodGen.getMethod(LazyMethodGen.java:484) org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:512) org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:652) org.aspectj.weaver.bcel.BcelWeaver.getClassFilesFor(BcelWeaver.java:1420) org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1390) And that is an exception on this line in remap() ih = ih.getNext(); called from the addExceptionHandlers() line: gen.addExceptionHandler( remap(r.getRealStart(), map), remap(r.getRealEnd(), map), remap(r.getHandler(), map), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType())); During weaving, an instruction list is augmented with extra entries representing where shadows start and end (method-call, method-execution, handler, etc). When weaving is complete we want to remove these temporary elements and use the remaining instructions to produce the method bytecode. Now sometimes these temporary entries are targeted by other elements (line number tags, local variable tags and exception handlers usually). During packing we use remap() to reposition the locations so they move off of temporary placeholders and onto real instructions that will make it out into the bytecode. What the above exception tells us is that we started walking over temporary placeholder entries, but before we came to a real instruction, we ran out of instructions! This cannot happen, and indicates something went seriously wrong, we should always encounter an instruction when remapping off a temporary element. After some digging it is actually the remap() call for the handler (not the start or end) that leads to the problem. The handler represents where to jump to in the code when an exception of the specified type occurs between the instructions pointed at by start and end. I sent a debug build to a user encountering this problem (I could not recreate it) and in that I was looking at where in fact the handler was pointing before we called remap(). I learned that when this problem occurs, the handler is not pointing to anywhere in the method currently being processed (not good). In a second debug build I tried to ascertain who was setting these handlers to point to nowhere. This debug never triggered, no-one was setting them to point to nowhere... I happened to notice whilst going through the instructions in the debug output that cobertura was being used, a coverage toolkit that works by doing bytecode manipulation to insert calls out to a library. AspectJ was being called after cobertura and I asked the user to try the steps the other way round - it worked fine. Indicating cobertura was doing something to the bytecode that gave us problems. After much messing about, I recreated it by applying around advice to within(*) to all the classes in rt.jar (I just used that as a very large standalone jar file I could weave into). I learned that Cobertura creates catch blocks that look a little different to what javac and other compilers create. The typical bytecode sequence a compiler produces for a catch block starts with a STORE instruction, to store the exception being caught (whether the body of the catch block uses it or not). But the cobertura catch blocks started with an INVOKESTATIC instruction, a call out to another method. What does this mean? It means the same instruction has two shadows, a 'handler' shadow and a 'method-call' shadow - and it turns out this is what causes our problem. If around advice is applied to the call join point and it cannot be inlined then the body of the call shadow (the call itself) is pulled out into a new method. Because the handler was the same instruction, this meant the handler *was also being pulled out* into the new method, leaving behind an exception handler that jumped to an invalid location (in fact it 'jumped' to an instruction in a different method!). So the reason I never saw the handler location being set incorrectly is that it was set correctly up front, but then dragged out with the method-call shadow into the wrong place. In bytecode terms it looks like this: method-execution() | ICONST_0 | ISTORE_2 | SIPUSH -1 | ISTORE_3 | catch java.lang.Exception (1806389629) -> E0 | | method-call(ProjectData ProjectData.getGlobalProjectData()) | | | INVOKESTATIC ProjectData.getGlobalProjectData () | | method-call(ProjectData getGlobalProjectData()) | | LDC "SomeString" | | method-call(ClassData getOrCreateClassData(java.lang.String)) | | | INVOKEVIRTUAL ProjectData.getOrCreateClassData (LString;) | | method-call(ClassData ProjectData.getOrCreateClassData(String)) | | SIPUSH 106 | | method-call(void ClassData.touch(int)) | | | INVOKEVIRTUAL ClassData.touch (I)V | | method-call(void ClassData.touch(int)) | | ALOAD_1 | | method-call(Object Expression.getValue()) | | | INVOKEVIRTUAL Expression.getValue () | | method-call(Object Expression.getValue()) | catch java.lang.Exception (1806389629) -> E0 | ARETURN | method-call(nProjectData ProjectData.getGlobalProjectData()) | | E0: INVOKESTATIC ProjectData.getGlobalProjectData () | method-call(ProjectData ProjectData.getGlobalProjectData()) | LDC "Object" We can see the problem in that final method-call. The target for the exception handler seen earlier (E0) is within the method-call shadow. What to do?
resolved fixed
5f97d46
AspectJ
https://github.com/eclipse/org.aspectj
eclipse/org.aspectj
java
null
null
null
2008-05-07T15:31:18Z
2008-05-07T03:13:20Z
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
if (canMatch(enclosingShadow.getKind()) && !(mg.getName().charAt(0)=='a' && mg.getName().startsWith("ajc$interFieldInit"))) { if (match(enclosingShadow, shadowAccumulator)) { enclosingShadow.init(); } } mg.matchedShadows = shadowAccumulator; return !shadowAccumulator.isEmpty(); } } private boolean matchInit(LazyMethodGen mg, List shadowAccumulator) { BcelShadow enclosingShadow; InstructionHandle superOrThisCall = findSuperOrThisCall(mg); if (superOrThisCall == null) return false; enclosingShadow = BcelShadow.makeConstructorExecution(world, mg, superOrThisCall); if (mg.getEffectiveSignature() != null) { enclosingShadow.setMatchingSignature(mg.getEffectiveSignature().getEffectiveSignature()); } boolean beforeSuperOrThisCall = true; if (shouldWeaveBody(mg)) { if (canMatchBodyShadows) { for (InstructionHandle h = mg.getBody().getStart(); h != null; h = h.getNext()) { if (h == superOrThisCall) { beforeSuperOrThisCall = false; continue;