Skip to content
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

Make read and write access to modified properties synchronized #568

Merged
merged 1 commit into from
May 2, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public abstract class ConfigurationLocation implements Cloneable, Comparable<Con
private NamedScope namedScope;

private boolean propertiesCheckedThisSession;
private long blockedUtil;
private long blockedUntil;

public ConfigurationLocation(@NotNull final ConfigurationType type,
@NotNull final Project project) {
Expand Down Expand Up @@ -95,15 +95,15 @@ public ConfigurationType getType() {
return type;
}

public String getLocation() {
public synchronized String getLocation() {
return location;
}

public Optional<NamedScope> getNamedScope() {
public synchronized Optional<NamedScope> getNamedScope() {
return Optional.ofNullable(this.namedScope);
}

public void setLocation(final String location) {
public synchronized void setLocation(final String location) {
if (isBlank(location)) {
throw new IllegalArgumentException("A non-blank location is required");
}
Expand All @@ -116,27 +116,27 @@ public void setLocation(final String location) {
this.propertiesCheckedThisSession = false;
}

public String getDescription() {
public synchronized String getDescription() {
return description;
}

public void setDescription(@Nullable final String description) {
public synchronized void setDescription(@Nullable final String description) {
if (description == null) {
this.description = location;
} else {
this.description = description;
}
}

public void setNamedScope(NamedScope namedScope) {
public synchronized void setNamedScope(NamedScope namedScope) {
this.namedScope = namedScope;
}

public Map<String, String> getProperties() {
public synchronized Map<String, String> getProperties() {
return new HashMap<>(properties);
}

public void setProperties(final Map<String, String> newProperties) {
public synchronized void setProperties(final Map<String, String> newProperties) {
properties.clear();

if (newProperties == null) {
Expand All @@ -148,11 +148,11 @@ public void setProperties(final Map<String, String> newProperties) {
this.propertiesCheckedThisSession = false;
}

public boolean isRemovable() {
public synchronized boolean isRemovable() {
return true;
}

public void reset() {
public synchronized void reset() {
propertiesCheckedThisSession = false;
unblock();
}
Expand Down Expand Up @@ -216,15 +216,15 @@ private void extractPropertyNames(final Element element, final List<String> prop
}

@SuppressWarnings("EmptyTryBlock")
public void ensurePropertiesAreUpToDate(@NotNull final ClassLoader checkstyleClassLoader) throws IOException {
public synchronized void ensurePropertiesAreUpToDate(@NotNull final ClassLoader checkstyleClassLoader) throws IOException {
if (!propertiesCheckedThisSession) {
try (InputStream ignored = resolve(checkstyleClassLoader)) {
// ignored
}
}
}

public InputStream resolve(@NotNull final ClassLoader checkstyleClassLoader) throws IOException {
public synchronized InputStream resolve(@NotNull final ClassLoader checkstyleClassLoader) throws IOException {
InputStream is = resolveFile(checkstyleClassLoader);

if (!propertiesCheckedThisSession) {
Expand All @@ -251,7 +251,7 @@ public InputStream resolve(@NotNull final ClassLoader checkstyleClassLoader) thr
}

@Nullable
public String resolveAssociatedFile(@Nullable final String filename,
public synchronized String resolveAssociatedFile(@Nullable final String filename,
@Nullable final Module module,
@NotNull final ClassLoader checkstyleClassLoader) throws IOException {
if (filename == null) {
Expand Down Expand Up @@ -357,7 +357,7 @@ private File checkModuleContentRoots(final Module module, final String fileName)
return null;
}

public final boolean hasChangedFrom(final ConfigurationLocation configurationLocation) {
public synchronized final boolean hasChangedFrom(final ConfigurationLocation configurationLocation) {
return !equals(configurationLocation)
|| propertiesHaveChanged(configurationLocation);
}
Expand All @@ -369,7 +369,7 @@ private boolean propertiesHaveChanged(final ConfigurationLocation configurationL
return !getProperties().equals(configurationLocation.getProperties());
}

public String getDescriptor() {
public synchronized String getDescriptor() {
assert location != null;
assert description != null;
assert namedScope != null;
Expand Down Expand Up @@ -474,19 +474,19 @@ private int compareStrings(@Nullable final String pStr1, @Nullable final String
}


public boolean isBlocked() {
return blockedUtil > currentTimeMillis();
public synchronized boolean isBlocked() {
return blockedUntil > currentTimeMillis();
}

public long blockedForSeconds() {
return Math.max((blockedUtil - currentTimeMillis()) / 1000, 0);
public synchronized long blockedForSeconds() {
return Math.max((blockedUntil - currentTimeMillis()) / 1000, 0);
}

public void block() {
blockedUtil = currentTimeMillis() + BLOCK_TIME_MS;
public synchronized void block() {
blockedUntil = currentTimeMillis() + BLOCK_TIME_MS;
}

public void unblock() {
blockedUtil = 0L;
public synchronized void unblock() {
blockedUntil = 0L;
}
}