Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
srijeet0406 committed Dec 8, 2023
commit 0b0d96ee5312ec1afde4e748a21e22d06df5d742
33 changes: 20 additions & 13 deletions src/main/java/org/xbill/DNS/Zone.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public boolean hasNext() {
}

@Override
public RRset next() {
public RRset next() throws IllegalMonitorStateException {
Comment thread
srijeet0406 marked this conversation as resolved.
Outdated
if (!hasNext()) {
throw new NoSuchElementException();
}
Expand Down Expand Up @@ -108,7 +108,7 @@ void setLock(ReentrantReadWriteLock.ReadLock lock) {
readLock = lock;
}

private void validate() throws IOException {
private void validate() throws IOException, IllegalMonitorStateException {
originNode = exactName(origin);
if (originNode == null) {
throw new IOException(origin + ": no data specified");
Expand Down Expand Up @@ -150,6 +150,7 @@ public Zone(Name zone, String file) throws IOException, IllegalMonitorStateExcep
data = new TreeMap<>();

if (zone == null) {
writeLock.unlock();
Comment thread
srijeet0406 marked this conversation as resolved.
Outdated
throw new IllegalArgumentException("no zone name specified");
}
try (Master m = new Master(file, zone)) {
Expand Down Expand Up @@ -211,7 +212,8 @@ private void fromXFR(ZoneTransferIn xfrin)
* @param xfrin The incoming zone transfer to execute.
* @see ZoneTransferIn
*/
public Zone(ZoneTransferIn xfrin) throws IOException, ZoneTransferException {
public Zone(ZoneTransferIn xfrin)
throws IOException, ZoneTransferException, IllegalMonitorStateException {
fromXFR(xfrin);
}

Expand All @@ -220,7 +222,8 @@ public Zone(ZoneTransferIn xfrin) throws IOException, ZoneTransferException {
*
* @see ZoneTransferIn
*/
public Zone(Name zone, int dclass, String remote) throws IOException, ZoneTransferException {
public Zone(Name zone, int dclass, String remote)
throws IOException, ZoneTransferException, IllegalMonitorStateException {
ZoneTransferIn xfrin = ZoneTransferIn.newAXFR(zone, remote, null);
xfrin.setDClass(dclass);
fromXFR(xfrin);
Expand Down Expand Up @@ -299,13 +302,15 @@ private RRset findRRset(Name name, int type) {
return oneRRset(types, type);
}

private void addRRset(Name name, RRset rrset) {
private void addRRset(Name name, RRset rrset) throws IllegalMonitorStateException {
writeLock.lock();
if (!hasWild && name.isWild()) {
hasWild = true;
}
Object types = data.get(name);
if (types == null) {
data.put(name, rrset);
writeLock.unlock();
return;
}
int rtype = rrset.getType();
Expand All @@ -316,6 +321,7 @@ private void addRRset(Name name, RRset rrset) {
RRset set = list.get(i);
if (set.getType() == rtype) {
list.set(i, rrset);
writeLock.unlock();
return;
}
}
Expand All @@ -331,6 +337,7 @@ private void addRRset(Name name, RRset rrset) {
data.put(name, list);
}
}
writeLock.unlock();
}

private void removeRRset(Name name, int type) throws IllegalMonitorStateException {
Expand Down Expand Up @@ -365,7 +372,7 @@ private void removeRRset(Name name, int type) throws IllegalMonitorStateExceptio
writeLock.unlock();
}

private SetResponse lookup(Name name, int type) {
private SetResponse lookup(Name name, int type) throws IllegalMonitorStateException {
if (!name.subdomain(origin)) {
return SetResponse.ofType(SetResponse.NXDOMAIN);
}
Expand Down Expand Up @@ -480,7 +487,7 @@ private RRset expandSet(RRset set, Name tname) {
* @return A SetResponse object
* @see SetResponse
*/
public SetResponse findRecords(Name name, int type) {
public SetResponse findRecords(Name name, int type) throws IllegalMonitorStateException {
return lookup(name, type);
}

Expand All @@ -492,7 +499,7 @@ public SetResponse findRecords(Name name, int type) {
* @return The matching RRset
* @see RRset
*/
public RRset findExactMatch(Name name, int type) {
public RRset findExactMatch(Name name, int type) throws IllegalMonitorStateException {
Object types = exactName(name);
if (types == null) {
return null;
Expand Down Expand Up @@ -556,7 +563,7 @@ public void removeRecord(Record r) throws IllegalMonitorStateException {
}

/** Returns an Iterator over the RRsets in the zone. */
public Iterator<RRset> iterator() {
public Iterator<RRset> iterator() throws IllegalMonitorStateException {
return new ZoneIterator(false);
}

Expand All @@ -565,11 +572,11 @@ public Iterator<RRset> iterator() {
* This is identical to {@link #iterator} except that the SOA is returned at the end as well as
* the beginning.
*/
public Iterator<RRset> AXFR() {
public Iterator<RRset> AXFR() throws IllegalMonitorStateException {
return new ZoneIterator(true);
}

private void nodeToString(StringBuffer sb, Object node) {
private void nodeToString(StringBuilder sb, Object node) throws IllegalMonitorStateException {
RRset[] sets = allRRsets(node);
for (RRset rrset : sets) {
rrset.rrs().forEach(r -> sb.append(r).append('\n'));
Expand All @@ -580,7 +587,7 @@ private void nodeToString(StringBuffer sb, Object node) {
/** Returns the contents of the Zone in master file format. */
public String toMasterFile() throws IllegalMonitorStateException {
readLock.lock();
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
nodeToString(sb, originNode);
for (Map.Entry<Name, Object> entry : data.entrySet()) {
if (!origin.equals(entry.getKey())) {
Expand All @@ -593,7 +600,7 @@ public String toMasterFile() throws IllegalMonitorStateException {

/** Returns the contents of the Zone as a string (in master file format). */
@Override
public String toString() {
public String toString() throws IllegalMonitorStateException {
return toMasterFile();
}
}