You need to sign in to do that
Don't have an account?

Method is not visible (problem with inheritance)
Hi,
I am having a problem with inheritance. I am not sure what I am doing wrong... please help.
I have an abstract class that looks like this:
public abstract class TokenHandlerAbstract {
protected Pattern p = null;
public Boolean isValid(String testString, TPParams params) {
Pattern p = getPattern();
return isPatternMatch(p, testString);
}
protected virtual Pattern getPattern() {
String regexp = functionName + '(.*)';
if ((p == null) || (p.pattern() != regexp)) {
p = Pattern.compile(regexp);
}
return p;
}
}
protected Pattern p = null;
public Boolean isValid(String testString, TPParams params) {
Pattern p = getPattern();
return isPatternMatch(p, testString);
}
protected virtual Pattern getPattern() {
String regexp = functionName + '(.*)';
if ((p == null) || (p.pattern() != regexp)) {
p = Pattern.compile(regexp);
}
return p;
}
}
This class is extended with a class that looks like this:
public class TokenHandlerString extends TokenHandlerAbstract {
protected override Pattern getPattern() {
// Anything surrounded by single quotes
String regexp = '\'.*\'';
if ((p == null) || (p.pattern() != regexp)) {
p = Pattern.compile(regexp);
}
return p;
}
}
protected override Pattern getPattern() {
// Anything surrounded by single quotes
String regexp = '\'.*\'';
if ((p == null) || (p.pattern() != regexp)) {
p = Pattern.compile(regexp);
}
return p;
}
}
These classes get called from a third class that looks like this:
public class TokenValueFinder {
private TokenHandlerString thString = new TokenHandlerString();
public String findValue(String testString, TPParams params) {
if (thString.isValid(testString, params)) {
...
}
}
}
private TokenHandlerString thString = new TokenHandlerString();
public String findValue(String testString, TPParams params) {
if (thString.isValid(testString, params)) {
...
}
}
}
When I view the page I get this error:
System.TypeException: Method is not visible: [TokenHandlerString].getPattern()
Class.TokenHandlerAbstract.isValid: line 7, column 21
Class.TokenValueFinder.findValue: line 31, column 20
Class.TPTextParser2.privateParse: line 35, column 31
Class.TPTextParser2.Parse: line 15, column 9
Class.TPResolved2.getTemplateResolved: line 198, column 28
External entry point
Class.TokenHandlerAbstract.isValid: line 7, column 21
Class.TokenValueFinder.findValue: line 31, column 20
Class.TPTextParser2.privateParse: line 35, column 31
Class.TPTextParser2.Parse: line 15, column 9
Class.TPResolved2.getTemplateResolved: line 198, column 28
External entry point
If I change the visibility of getPattern() from protected to public, the error goes away. But why?
I understand that isValid()has to be public because I am calling the method from a different class. But getPattern() is being called from the same class or one that inherits from it.
Thanks
Andres Perez

This test code works for me:
Code:
This reproduces your case scenario, but not the bug you are encountering. Try executing that (Execute Immediate) to see if you get any error.
If you do get an error, then I would surmise that they are not finished rolling out support for protected methods.