Skip to content
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
42 changes: 12 additions & 30 deletions java/ql/lib/semmle/code/java/Overlay.qll
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ predicate isOverlay() { databaseMetadata("isOverlay", "true") }
overlay[local]
string getRawFile(@locatable el) {
exists(@location loc, @file file |
hasLocation(el, loc) and
(hasLocation(el, loc) or xmllocations(el, loc)) and
locations_default(loc, file, _, _, _, _) and
files(file, result)
)
Comment on lines 19 to 24
Copy link
Preview

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Please add a short doc comment clarifying that getRawFile now handles XML locatables via xmllocations in addition to standard locations, since this broadens the function’s scope and improves discoverability.

Copilot uses AI. Check for mistakes.

Expand Down Expand Up @@ -73,40 +73,22 @@ private predicate discardReferableLocatable(@locatable el) {
)
}

/** Gets the raw file for a configLocatable. */
overlay[local]
private predicate baseConfigLocatable(@configLocatable l) { not isOverlay() and exists(l) }

overlay[local]
private predicate overlayHasConfigLocatables() {
isOverlay() and
exists(@configLocatable el)
}

overlay[discard_entity]
private predicate discardBaseConfigLocatable(@configLocatable el) {
// The properties extractor is currently not incremental, so if
// the overlay contains any config locatables, the overlay should
// contain a full extraction and all config locatables from base
// should be discarded.
baseConfigLocatable(el) and overlayHasConfigLocatables()
}

overlay[local]
private predicate baseXmlLocatable(@xmllocatable l) {
not isOverlay() and not files(l, _) and not xmlNs(l, _, _, _)
private string getRawFileForConfig(@configLocatable el) {
exists(@location loc, @file file |
configLocations(el, loc) and
locations_default(loc, file, _, _, _, _) and
files(file, result)
)
Comment on lines +76 to +83
Copy link
Preview

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider making the doc a bit more explicit, e.g., “Returns the raw file path for a config locatable using configLocations; used to drive overlayChangedFiles-based discarding.” This clarifies how the function is used and why configLocations is the source.

Copilot uses AI. Check for mistakes.

}

overlay[local]
private predicate overlayHasXmlLocatable() {
isOverlay() and
exists(@xmllocatable l | not files(l, _) and not xmlNs(l, _, _, _))
private string baseConfigLocatable(@configLocatable el) {
not isOverlay() and result = getRawFileForConfig(el)
}

overlay[discard_entity]
private predicate discardBaseXmlLocatable(@xmllocatable el) {
// The XML extractor is currently not incremental, so if
// the overlay contains any XML locatables, the overlay should
// contain a full extraction and all XML locatables from base
// should be discarded.
baseXmlLocatable(el) and overlayHasXmlLocatable()
private predicate discardBaseConfigLocatable(@configLocatable el) {
overlayChangedFiles(baseConfigLocatable(el))
}
11 changes: 11 additions & 0 deletions java/ql/lib/semmle/code/xml/XML.qll
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module;

import semmle.files.FileSystem
private import codeql.xml.Xml
private import semmle.code.java.Overlay

private module Input implements InputSig<File, Location> {
class XmlLocatableBase = @xmllocatable or @xmlnamespaceable;
Expand Down Expand Up @@ -69,3 +70,13 @@ private module Input implements InputSig<File, Location> {
}

import Make<File, Location, Input>

private class DiscardableXmlAttribute extends DiscardableLocatable, @xmlattribute { }

private class DiscardableXmlElement extends DiscardableLocatable, @xmlelement { }

private class DiscardableXmlComment extends DiscardableLocatable, @xmlcomment { }

private class DiscardableXmlCharacters extends DiscardableLocatable, @xmlcharacters { }

private class DiscardableXmlDtd extends DiscardableLocatable, @xmldtd { }
Comment on lines +74 to +82
Copy link
Preview

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding a brief comment explaining why these XML entities are marked discardable and that XML namespaces are intentionally excluded due to non-file-local TRAP keys. This will help future readers understand the scope and rationale of discard behavior.

Copilot uses AI. Check for mistakes.

Loading