Skip to content

Commit

Permalink
fix string npe
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Jun 25, 2023
1 parent cdabf77 commit a3ec80f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/main/java/com/reandroid/arsc/array/StringArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public abstract class StringArray<T extends StringItem> extends OffsetBlockArray<T> implements JSONConvert<JSONArray> {
Expand Down Expand Up @@ -51,7 +52,7 @@ protected void onPostShift(int index){
@Override
protected void onPreRefreshRefresh(){
if(isFlexible()){
trimAllocatedFreeSpace();
trimNullBlocks();
}
super.onPreRefreshRefresh();
}
Expand Down Expand Up @@ -85,8 +86,10 @@ List<T> listUnusedStringsToRemove(){
}
public List<T> listUnusedStrings(){
List<T> results=new ArrayList<>();
for(T item:listItems()){
if(!item.hasReference()){
T[] childes = getChildes();
for(int i = 0; i < childes.length; i++){
T item = childes[i];
if(item != null && !item.hasReference()){
results.add(item);
}
}
Expand All @@ -96,12 +99,15 @@ public void setUtf8(boolean is_utf8){
if(mUtf8==is_utf8){
return;
}
mUtf8=is_utf8;
T[] childes=getChildes();
mUtf8 = is_utf8;
T[] childes = getChildes();
if(childes!=null){
int max=childes.length;
for(int i=0;i<max;i++){
childes[i].setUtf8(is_utf8);
int length = childes.length;
for(int i=0; i<length; i++){
T item = childes[i];
if(item != null){
item.setUtf8(is_utf8);
}
}
}
}
Expand All @@ -124,10 +130,9 @@ public JSONArray toJson(boolean styledOnly) {
}
JSONArray jsonArray=new JSONArray();
int i=0;
for(T item:listItems()){
if(item.isNull()){
continue;
}
Iterator<T> itr = iterator(true);
while (itr.hasNext()){
T item = itr.next();
if(styledOnly && !item.hasStyle()){
continue;
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/reandroid/arsc/base/BlockArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ public final T get(int i){
}
return elementData[i];
}
public final T getLast(){
return get(childesCount() - mFreeSpace - 1);
}
public int indexOf(Object block){
T[] items=elementData;
if(items==null){
Expand Down Expand Up @@ -354,9 +357,11 @@ public Iterator<T> iterator() {
return iterator(false);
}
public Iterator<T> iterator(boolean skipNullBlock) {
trimAllocatedFreeSpace();
return new BlockIterator(skipNullBlock);
}
public Iterator<T> iterator(Predicate<T> tester) {
trimAllocatedFreeSpace();
return new PredicateIterator(tester);
}
public boolean contains(Object block){
Expand Down Expand Up @@ -457,6 +462,8 @@ private int countNonNull(boolean is_null_check){
return result;
}
private void changeSize(int amount){
mFreeSpace = 0;
mAllocateStep = 0;
T[] old=elementData;
int index=old.length;
int size=index+amount;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/reandroid/arsc/pool/StringPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ public boolean contains(String str){
public final T get(int index){
return mArrayStrings.get(index);
}
public final T getLast(){
return mArrayStrings.getLast();
}
public final StringGroup<T> get(String str){
return mUniqueMap.get(str);
}
Expand Down

0 comments on commit a3ec80f

Please sign in to comment.