Skip to content

Java: Revert #10489 and #10640 #10671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

33 changes: 0 additions & 33 deletions java/ql/lib/semmle/code/java/CompilationUnit.qll
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,5 @@ class CompilationUnit extends Element, File {
*/
Module getModule() { cumodule(this, result) }

/**
* Gets a type which is available in the top-level scope of this compilation unit.
* This can be a type:
* - declared in this compilation unit as top-level type
* - imported with an `import` declaration
* - declared in the same package as this compilation unit
* - declared in the package `java.lang`
*
* This predicate not consider "shadowing", it can have types as result whose simple name is
* shadowed by another type in scope.
*/
ClassOrInterface getATypeInScope() {
// See "Shadowing", https://docs.oracle.com/javase/specs/jls/se17/html/jls-6.html#jls-6.4.1
// Currently shadowing is not considered
result.(TopLevelType).getCompilationUnit() = this
or
exists(Import importDecl | importDecl.getCompilationUnit() = this |
result =
[
importDecl.(ImportStaticTypeMember).getATypeImport(),
importDecl.(ImportType).getImportedType(),
importDecl.(ImportStaticOnDemand).getATypeImport(),
importDecl.(ImportOnDemandFromType).getAnImport(),
importDecl.(ImportOnDemandFromPackage).getAnImport(),
]
)
or
// From same package or java.lang, see https://docs.oracle.com/javase/specs/jls/se17/html/jls-7.html
result.(TopLevelType).getPackage() = this.getPackage()
or
result.(TopLevelType).getPackage().hasName("java.lang")
}

override string getAPrimaryQlClass() { result = "CompilationUnit" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

import java

ClassOrInterface getTaggedType(ThrowsTag tag) {
RefType getTaggedType(ThrowsTag tag) {
result.hasName(tag.getExceptionName()) and
result = tag.getFile().(CompilationUnit).getATypeInScope()
exists(ImportType i | i.getFile() = tag.getFile() | i.getImportedType() = result)
}

// Uses ClassOrInterface as type for thrownType to also cover case where erroneously an interface
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
| ImpossibleJavadocThrows.java:9:5:9:12 | @throws | Javadoc for bad1 claims to throw InterruptedException but this is impossible. |
| ImpossibleJavadocThrows.java:16:5:16:15 | @exception | Javadoc for bad2 claims to throw Exception but this is impossible. |
| ImpossibleJavadocThrows.java:23:5:23:12 | @throws | Javadoc for bad3 claims to throw Runnable but this is impossible. |
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ public void bad1() {
public void bad2() {
}

/**
*
* @throws Runnable
*/
public void bad3() {
}

/**
*
* @throws InterruptedException
Expand Down