Skip to content

Commit c8656e7

Browse files
committed
add a test to expect exception
1 parent 664ce2b commit c8656e7

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.parquet;
20+
21+
public class UntrustedStringableClass {
22+
23+
private final String value;
24+
25+
public UntrustedStringableClass(String value) {
26+
this.value = value;
27+
}
28+
29+
@Override
30+
public String toString() {
31+
return this.value;
32+
}
33+
34+
@Override
35+
public boolean equals(Object other) {
36+
return other instanceof UntrustedStringableClass && this.value.equals(((UntrustedStringableClass) other).value);
37+
}
38+
}

parquet-avro/src/test/java/org/apache/parquet/avro/TestReflectReadWrite.java

+35
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.avro.util.Utf8;
3838
import org.apache.hadoop.conf.Configuration;
3939
import org.apache.hadoop.fs.Path;
40+
import org.apache.parquet.UntrustedStringableClass;
4041
import org.apache.parquet.hadoop.ParquetReader;
4142
import org.apache.parquet.hadoop.ParquetWriter;
4243
import org.apache.parquet.hadoop.metadata.CompressionCodecName;
@@ -76,6 +77,40 @@ public void testWriteReflectReadGeneric() throws IOException {
7677
}
7778
}
7879

80+
@Test(expected = SecurityException.class)
81+
public void testUntrustedStringableClass() throws IOException {
82+
new AvroConverters.FieldStringableConverter(
83+
new ParentValueContainer() {
84+
@Override
85+
public void add(Object value) {}
86+
87+
@Override
88+
public void addBoolean(boolean value) {}
89+
90+
@Override
91+
public void addInt(int value) {}
92+
93+
@Override
94+
public void addLong(long value) {}
95+
96+
@Override
97+
public void addFloat(float value) {}
98+
99+
@Override
100+
public void addDouble(double value) {}
101+
102+
@Override
103+
public void addChar(char value) {}
104+
105+
@Override
106+
public void addByte(byte value) {}
107+
108+
@Override
109+
public void addShort(short value) {}
110+
},
111+
UntrustedStringableClass.class);
112+
}
113+
79114
private GenericRecord getGenericPojoUtf8() {
80115
Schema schema = ReflectData.get().getSchema(Pojo.class);
81116
GenericData.Record record = new GenericData.Record(schema);

0 commit comments

Comments
 (0)